How do I synchronize moving objects?

Post your scripting questions / solutions here

Moderator: Moderators

User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

nope

Post by tltrude »

No, it is the same.
Tom Trude,

Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Try this:

Code: Select all


pole_prep:

local.POLE_SEPERATION = 3680 // distance between poles
local.SPEED = 1536.0 // terrain speed (3 X 512)

local.poles = $pole1::$pole2::$pole3::$pole4

local.basepoint = $polewayA.origin
local.movevec = $polewayB2.origin - local.basepoint
local.trackdist = vector_length local.movevec
local.dirvec = (1.0 / local.trackdist) * local.movevec // unit vector
local.poles[1].origin = $polewayA.origin
local.dist = 0.0 // distance travelled

//pole movement loop

while(1)
{
   // space the poles along the track
   for(local.i = 1; local.i <= local.poles.size; local.i++)
   {
      local.pole = local.poles[local.i]
      local.pole show
      local.dist_on_track = local.dist + local.POLE_SEPERATION * (local.i - 1)
      if(local.dist_on_track > local.trackdist)
      {
         // move back to the beginning
         local.dist_on_track -= local.trackdist
         local.pole hide
      }
      local.pole.origin = local.basepoint + local.dist_on_track * local.dirvec
   }
   waitframe
   local.dist += local.SPEED * 0.05
   
   // this is only to prevent the dist variable from getting too large
   if(local.dist > local.trackdist)
      local.dist -= local.trackdist
}
 
end 
I only added a local.pole show and a local.pole hide line... no idea if it makes a difference :?
Image
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

nope

Post by tltrude »

Does not work. The poles that have returned stay hidden untill all four poles have returned. Then they all show at the same time and it starts all over again. Also the "hide" does not happen fast enough, so the returning poles still flicker on there way back to the start point.
Tom Trude,

Image
Shuriken1
Corporal
Posts: 28
Joined: Thu Sep 02, 2004 3:05 pm
Contact:

Post by Shuriken1 »

Please excuse my stupidity but whats wrong with:

Code: Select all

local.poles[1] hide
local.poles[1] time .005 
local.poles[1] moveto $polewayA 
local.poles[1] waitmove
local.poles[1] show
Shuriken1
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

moveto

Post by tltrude »

Nothing, but that is originally how I had it and the poles got out of sync with each other.

I tryed this, but it seems to ignore the moveto lines.

Code: Select all

      if(local.dist_on_track > local.trackdist) 
      { 
         // move back to the beginning
         local.pole time .001
         local.pole moveto $polewayC
         waitmove
         local.pole moveto $polewayD
         waitmove
         local.dist_on_track -= local.trackdist 
      } 
Last edited by tltrude on Fri Sep 03, 2004 2:03 am, edited 1 time in total.
Tom Trude,

Image
Shuriken1
Corporal
Posts: 28
Joined: Thu Sep 02, 2004 3:05 pm
Contact:

Post by Shuriken1 »

Could you have something that is in infinitely looping round waiting for something to enter the final position, ie. the final waypoint of the loop and move it back to the starting position. I'm not sure how you would code that, I just can't help thinking there is a much more simple method :?
Shuriken1
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

array

Post by tltrude »

I think the problem is that it uses a "Constant array" rather than a "Targetname array" for the poles. Would it be better to just name all the poles "pole" and then index them with a for loop?
Tom Trude,

Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Re: array

Post by jv_map »

tltrude wrote:I think the problem is that it uses a "Constant array" rather than a "Targetname array" for the poles. Would it be better to just name all the poles "pole" and then index them with a for loop?
I can't see why that would matter :?
Image
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

SO?

Post by tltrude »

So, how do I fix it?
I don't really understand how your thread moves the poles.
Is it changing the poles origin by one unit 14720 times?
What does (-=) and (+=) mean?
Can I replace "local.basepoint" with "$polewayA.origin"?
I'm guessing that to get the pole to go back, the vector direction is reversed from ( 0 -14720 0) to ( 0 14720 0).
Am I right?
Tom Trude,

Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Re: SO?

Post by jv_map »

tltrude wrote:So, how do I fix it?
I don't really understand how your thread moves the poles.
Is it changing the poles origin by one unit 14720 times?
What does (-=) and (+=) mean?
local.a -= local.b means local.a = local.a - local.b, and similar for +=. Hence the origin of the poles does not increase with 1 unit but with 0.05 * local.SPEED each frame :)
Can I replace "local.basepoint" with "$polewayA.origin"?
Yes... I personally hate to use targetnames all throughout a script because they may be subject to change... hence I usually store them in some universal variable somewhere at the top of the script... it's only personal preference though so you can change it as you like.
I'm guessing that to get the pole to go back, the vector direction is reversed from ( 0 -14720 0) to ( 0 14720 0).
Am I right?
No not at all ;) .. the pole doesn't actually move back...

Quote:

Code: Select all

      if(local.dist_on_track > local.trackdist)
      {
         // move back to the beginning
         local.dist_on_track -= local.trackdist
      } 
      local.pole.origin = local.basepoint + local.dist_on_track * local.dirvec 
This little bit of code checks if a pole has exceeded the length of the track, and if it is the distance of the track is subtracted from its current distance from the startpoint. Hence, say a pole has passed the last waypoint by 10 units, it's dist_on_track would be trackdist + 10, and the if block would change that to trackdist + 10 - trackdist = 10 so the pole is placed at 10 units from the start waypoint.

Hope this clears it up somehow :?
Image
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

ok

Post by tltrude »

Thanks, that helped a lot! But, I still don't understand why I can't get the retuning pole to loop underground. Below is the script with all the know value variables removed. It worked the same as before until I added an offset. Now, all four poles stay underground until they get to polewayB. Then they all pop up together and start sending the poles back one by one to be assembled underground again.

So basically, I don't know why the four poles act as one. Nor do I understand why they pop up 3680 units before they reach polewayB2 (the endpoint) and not one by one at polewayA.

Code: Select all

// Test poles
// ARCHITECTURE: ATOMIC
// SCRIPTING: ATOMIC & TLTRUDE

main:

// set scoreboard messages
setcvar "g_obj_alliedtext1" "test poles!"
setcvar "g_obj_alliedtext2" ""
setcvar "g_obj_alliedtext3" ""
setcvar "g_obj_axistext1" ""
setcvar "g_obj_axistext2" ""
setcvar "g_obj_axistext3" ""

setcvar "g_scoreboardpic" ""

	level waittill prespawn
 
	//***Precache Dm Stuff
	exec global/DMprecache.scr
	level.script = maps/dm/test_jpoles.scr
	exec global/ambient.scr m6l3a // for background sound

	spawn info_waypoint targetname "polewayB2"
	$polewayB2.origin = ($polewayB.origin + ( -3680 0 0 ))

	thread pole_prep

	level waittill spawn 

end

//------------------------------>
// Pole Thread
//------------------------------>

pole_prep: 

local.poles = $pole1::$pole2::$pole3::$pole4 

local.poles[1].origin = $polewayA.origin 
local.dist = 0.0

//pole movement loop 

while(1) 
{ 
   for(local.i = 1; local.i <= local.poles.size; local.i++) 
   { 
      local.poles[local.i].offset = ( 0 0 0 ) 
      local.pole = local.poles[local.i] 
      local.dist_on_track = local.dist + 3680 * (local.i - 1) 
      if( local.dist_on_track > 14720 ) 
      { 
         local.dist_on_track = ( local.dist_on_track - 14720 ) 
         local.poles[local.i].offset = ( 0 0 -1000 ) 
      } 
      local.pole.origin = $polewayA.origin + ((local.dist_on_track * ( -1 0 0 )) + local.poles[local.i].offset )
   } 
   waitframe 
   local.dist = ( local.dist + 76.8 ) 
   if( local.dist > 14720 ) 
      local.dist = ( local.dist - 14720 ) 
} 
  
end
There are two waypoints underground ($polewayC and $polewayD) which are not being used, and $polewayB is only being used as a reference to spawn $polewayB2. I can add a fifth pole, if needed.
I am sorry to be such a pest about this, but your thread is unuseable if the poles return above ground.
Tom Trude,

Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Hmm :? well here's some things you could still try:

- Use plain Entities instead of ScriptSlaves.
- Instead of local.pole.origin = (x y z) use local.pole origin (x y z)
- Try the below commands:
local.pole stationary
local.pole effects "+antisbjuice"

Here's a convenient method for turning a script_object into an Entity:

Code: Select all

local.script_object_poles = $pole1::$pole2::$pole3::$pole4
for(local.i = 1; local.i <= local.script_object_poles.size; local.i++)
{
  local.poles[local.i] = waitthread reclassobject local.script_object_poles[local.i] Entity
}

// (...)

// -------------------
// spawns a new object with same brushmodel and removes old object
reclassobject local.object local.newclass:
  local.newobj = spawn local.newclass origin local.object.origin angles local.object.angles model local.object.brushmodel
  local.object remove
end local.newobj
Image
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

strange

Post by tltrude »

A strange thing happened. I increased the distance between wayponts to 18400 units and added a fifth pole. Now I can not see the returning poles! It still needs to be tested on the full map.

It might be that the map just has a little more or less fps and that what fixed it. I have been testing terrain brushes on the test map too, and they may have caused the change.

I tried the "entity" thing and it works, but it does not seem to do anything different for the 5 poles version. I did not try it with 4 poles. I don't know how, or where, to use those other two new lines.

Code: Select all

main:

// set scoreboard messages
setcvar "g_obj_alliedtext1" "test poles!"
setcvar "g_obj_alliedtext2" ""
setcvar "g_obj_alliedtext3" ""
setcvar "g_obj_axistext1" ""
setcvar "g_obj_axistext2" ""
setcvar "g_obj_axistext3" ""

setcvar "g_scoreboardpic" ""

	level waittill prespawn
 
	//***Precache Dm Stuff
	exec global/DMprecache.scr
	level.script = maps/dm/test_jpoles.scr
	exec global/ambient.scr m6l3a // for background sound

	spawn info_waypoint targetname "polewayB2"
	$polewayB2.origin = ($polewayB.origin + ( -3760 0 0 ))
	spawn info_waypoint targetname "polewayA2"
	$polewayA2.origin = ($polewayA.origin + ( 3600 0 0 ))

	thread pole_prep

	level waittill spawn 

end

//------------------------------>
// Pole Thread
//------------------------------>

pole_prep: 

local.poles = $pole1::$pole2::$pole3::$pole4::$pole5 

local.poles[1].origin = $polewayA2.origin
local.dist = 0.0

//poles movement loop 

while(1) 
{  
   for(local.i = 1; local.i <= local.poles.size; local.i++) 
   { 
      local.pole = local.poles[local.i] 
      local.dist_on_track = local.dist + 3680 * (local.i - 1) 
      if( local.dist_on_track > 18400 ) 
      { 
         local.dist_on_track = ( local.dist_on_track - 18400 ) 
      } 
      local.pole.origin = $polewayA2.origin + (local.dist_on_track * ( -1 0 0 ))
   } 
   waitframe 
   local.dist = ( local.dist + 76.8 ) 
   if( local.dist > 18400 ) 
      local.dist = ( local.dist - 18400 )
} 
  
end
Tom Trude,

Image
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

test

Post by tltrude »

I tested it in the full size map and all is well. so, a big thanks to you jv_map!!!!!!!!!!!
Tom Trude,

Image
User avatar
At0miC
General
Posts: 1164
Joined: Fri Feb 27, 2004 11:29 pm
Location: The Netherlands

Post by At0miC »

Yay! 8-), thanks m8
Post Reply