.MoveTo() teleports to position [Solved with workaround]
by Christian · in Torque 2D Beginner · 12/22/2013 (2:05 am) · 3 replies
Hey,
I've been noticing that an object that is moving towards a point with %obj.MoveTo(%pos, %speed) will teleport to the %pos if it doesn't get there in time.
For example:
There is an object going from point A to point B. Halfway to reaching point B, it hits a teleporter and is transported to point C. Now it continues it's movement towards point B. If it doesn't get there in time (I believe this is the normal time it would have taken it if the teleporter didn't happen), then it will will transport itself to point B.
I'm wondering if this is intentional in the .MoveTo functionality, and if so, are there any good alternative's to .MoveTo?
Thanks a bunch.
I've been noticing that an object that is moving towards a point with %obj.MoveTo(%pos, %speed) will teleport to the %pos if it doesn't get there in time.
For example:
There is an object going from point A to point B. Halfway to reaching point B, it hits a teleporter and is transported to point C. Now it continues it's movement towards point B. If it doesn't get there in time (I believe this is the normal time it would have taken it if the teleporter didn't happen), then it will will transport itself to point B.
I'm wondering if this is intentional in the .MoveTo functionality, and if so, are there any good alternative's to .MoveTo?
Thanks a bunch.
#2
And there's a flag to disable the warp:
12/22/2013 (8:41 am)
This is actually intentional - there were times when an object would not reach the intended destination because of physics settings and this was put in place to force the object to fit the intended behavior (the Blackjack Template needed this). For the vast majority of cases this works perfectly and allows you to rely on the onMoveToComplete() callback firing reasonably close to the time expected.And there's a flag to disable the warp:
ConsoleMethod(SceneObject, moveTo, bool, 4, 7, "(worldPoint X/Y, speed, [autoStop = true], [warpToTarget = true]) - Moves the object to the specified world point.n"
"The point is moved by calculating the initial linear velocity required and applies it.n"
"The object may never reach the point if it has linear damping applied or collides with another object.n"
"@param worldPoint/Y The world point to move the object to.n"
"@param speed The speed (in m/s) to use to move to the specified point."
"@param autoStop? Whether to automatically set the linear velocity to zero when time has elapsed or notn"
"@param warpToTarget? Whether to move instantly to the target point after the specified time or not in-case the target was not quite reached.n"
"@return Whether the move could be started or not.")So this should stop it as well:%sprite.moveTo(%destPoint, %speed, false, false);The sprite should continue moving in the last direction at the last given speed until it reaches the destination. If you actually teleport the sprite somewhere else you might need to call moveTo() again to update the move vector, but the system already allows for slowdowns and interruptions and probably updates direction to reach assigned destination during integration. You can always use isMoveComplete() to check and manually force a "warp" if necessary.
#3
12/22/2013 (12:58 pm)
Gotcha. Thanks Richard.
Torque Owner Christian