Game Development Community

Using .moveto on a moving target

by Shaz · in Torque Game Builder · 09/04/2008 (11:40 pm) · 5 replies

Is there any way to move to "an object" rather than to a position?

If I execute a .moveto with the destination set as %target.position, it works nicely if %target is stationary. But if %target is moving, by the time my object reaches the destination, it's no longer where I want it to move.

All I can think of is to break the move down into several smaller chunks, scheduled, and with each iteration, check the location of the target. This way there are a few direction changes along the way, and I end up closer to, but again not exactly, where I want to be.

If I could move to "an object" rather than a fixed position, the move function itself could continually check whether that object is moving, and update the vector and speed accordingly. This would result in much smoother direction changes and ending up much closer to the desired target.

Any way, other than what I've already said?

#1
09/05/2008 (1:21 am)
I think that is basically what you want to do. If you want more precision you could do the movoto every tick or even every frame. It would be easy to do this within a behavior because they already have callbacks that occur on those intervals.
#2
09/05/2008 (2:30 am)
Thanks.

Er - what's the difference between a tick and a frame, and which is the equivalent of what happens in the onUpdate callback?
#3
09/05/2008 (3:06 am)
If you're familiar with C++ or program development in general, a main loop it typically used to update the program. In this case, we use "ticks", which are defined as 1/32th of a second. So, every 1/32th of a second, the game processes a "tick".

I believe, in this case, James is also laveling a "frame" as a tick.

The onUpdate callback happens every tick/frame, whichever one you'd like to label it as (or 32 times a second).
#4
09/05/2008 (12:14 pm)
OnUpdate occurs every tick (32milliseconds). I was under the impression that there was also a behavior callback that occurs each rendered-frame (that's what I meant by frame). There might not actually be, but there is a t2dSceneGraph callback for this, t2dSceneGraph::onUpdateScene(%this).
#5
09/05/2008 (3:10 pm)
Thanks to you both. That's handy to know.