MoveTo() -- no callback if already at the target location
by Tom Bak · in Torque Game Builder · 07/25/2007 (10:01 pm) · 6 replies
Hey,
I'm not sure if this is a bug or as designed, but I just thought i'd bring it up to see what everybody else thinks.
If you call moveTo() and your scene object is already at the target location, the onPositionTarget() callback will never be called.
For example
will cause the callback to be called. However
will never call the callback.
If you have things randomly moving around the screen, it is possible that a particular object may just happen to be where its target destination is. Having to check for this in EVERY moveTo() call maybe isn't such a good idea. This result is very rare, which makes it difficult to debug why exactly your game sometimes doesn't behave how its supposed to and has decided to soft crash instead.
IMHO the onPositionTarget() callback should be called in both cases. This way you can just set it and forget it, and you will get consistent results without having to worry about where your object currently is.
Comments? Suggestions? :)
Tom
I'm not sure if this is a bug or as designed, but I just thought i'd bring it up to see what everybody else thinks.
If you call moveTo() and your scene object is already at the target location, the onPositionTarget() callback will never be called.
For example
%foo.moveTo( %foo.getPositionX()[b]+5[/b], %foo.getPositionY(), 50, true, true, true, 0.1 );
will cause the callback to be called. However
%foo.moveTo( %foo.getPositionX(), %foo.getPositionY(), 50, true, true, true, 0.1 );
will never call the callback.
If you have things randomly moving around the screen, it is possible that a particular object may just happen to be where its target destination is. Having to check for this in EVERY moveTo() call maybe isn't such a good idea. This result is very rare, which makes it difficult to debug why exactly your game sometimes doesn't behave how its supposed to and has decided to soft crash instead.
IMHO the onPositionTarget() callback should be called in both cases. This way you can just set it and forget it, and you will get consistent results without having to worry about where your object currently is.
Comments? Suggestions? :)
Tom
#2
07/26/2007 (11:36 am)
My vote: I think it should fire the callback even if it doesn't have to move. I have had to write special conditionals many times to take care of the case when an object is already at its MoveTo destination.
#3
07/26/2007 (9:46 pm)
Is this a bug? My project is displaying this behavior too, and I don't know how to work around it... if I shoot a particle from my own character targetting him or someone really close to him it will hang my game, because it depends on the objects onPositionTarget event going off :(
#4
Hope that made sense :)
07/26/2007 (9:52 pm)
Sounds like a bug to me, but an easy way to work around this would be to replace all your moveTo's with moveToWithCheck or something on the object that checks if the onPositionTarget callback should be thrown immediately (and if so, do it) and then call MoveTo if the object isn't next to the target. Definitely annoying since you'd probably end up putting the same extra function on a few classes, but that would fix it. If you just have a bullet class or something, I'd be easy.Hope that made sense :)
#5
try to use
error (%foo.getpositionx()) ==> check your positionx value
%foo.moveTo( %foo.getPositionX()+5, %foo.getPositionY(), 50, true, true );
/*i usually write this script rather than %foo.moveTo( %foo.getPositionX()+5, %foo.getPositionY(), 50, true, true, true, 0.1 ); and it always works*/
function sprite::Onpositiontarget(%this)
{
error("End moveto"SPC %this.getpositionx())
}
If there is no error message "Endmoveto" on the console
I only can guess 1 thing
Your sprite never reach the end position ( maybe it is caused by the world limit ) so there is no callback function
07/27/2007 (5:40 pm)
From what my experiencetry to use
error (%foo.getpositionx()) ==> check your positionx value
%foo.moveTo( %foo.getPositionX()+5, %foo.getPositionY(), 50, true, true );
/*i usually write this script rather than %foo.moveTo( %foo.getPositionX()+5, %foo.getPositionY(), 50, true, true, true, 0.1 ); and it always works*/
function sprite::Onpositiontarget(%this)
{
error("End moveto"SPC %this.getpositionx())
}
If there is no error message "Endmoveto" on the console
I only can guess 1 thing
Your sprite never reach the end position ( maybe it is caused by the world limit ) so there is no callback function
#6
If the current rotation of the scene object is equal the destination rotation than onRotationTarget () callback will never be called.
08/06/2007 (3:22 am)
The function onRotationTarget() show the same beheavor!If the current rotation of the scene object is equal the destination rotation than onRotationTarget () callback will never be called.
Torque 3D Owner Marc Dreamora Schaerer
Gayasoft