Game Development Community

OnPositionTarget not working?

by John Klimek · in Torque Game Builder · 03/11/2006 (2:37 pm) · 6 replies

I'm tying to move an object to a certain position and then have a callback called.

For example:

$ball = new t2dStaticSprite() { scenegraph = t2dScene; imagemap = ggLogoImageMap; };
$ball.setSize("10 10");
$ball.setPosition("-10 -10");
$ball.setImmovable(true); // so physics are deactivated
$ball.setPositionTarget("0 0", false, true true, 0.0);
$ball.moveTo("0 0", 10);

function t2dSceneObject::onPositionTarget(%this)
{
  echo("reached!");   
}

The onPositionTarget is never called... I've tried naming the function t2dStaticSprite::onPositionTarget but that didn't help.

Am I doing something wrong?

Thanks =)

#1
03/11/2006 (3:23 pm)
A few points:

1. there's a typo in your example (a comma missing between the two true values)
2. you've set the tolerance to 0.0 -- if it misses by a hair it misses by a mile
3. because you've set the tolerance to 0.0 there's no point in leaving 'snap' set to true -- there's nothing to do
#2
03/11/2006 (6:18 pm)
Oh, sorry for the typo. In the actual code there is no typo... (I retyped the code for the message and must have made the typo)

Shouldn't moveTo move exactly to the point I specify? I want my ball to move EXACTLY to "0 0" and then notify me... I don't want it to move to 0.999 and then notify me.... (therefore 0.0 tolerance)
#3
03/11/2006 (9:22 pm)
Computer numbers (other than integer) are not exact. How inexact depends on too many variables to be certain (e.g., the size of the mantissa for floating point which will be hardware dependent). Unless you know the mathematical behavior it is more reliable to give some leeway. The point of the 'snap' option is to have some leeway and still be able to say that it is exactly* where you want it.

*exactly is a relative term and strictly speaking the number may not be exactly what it appears to be. If you read my post in your other thread I give some more detail. The study of numerical methods covers this. While it isn't necessary to understand how all of this works to write torquescript it can help explain why things are the way they are.
#4
03/13/2006 (7:47 am)
I avoided to use this system because sometimes objects are
stoped in their way and I didn't know how to handle this, then the callback was
never called.
#5
03/14/2006 (5:23 am)
Hmmm... I'm still a bit confused then.

To make sure everything is in sync for my multiplayer game I'm creating a path for my objects to travel and then transmitting the path to each client (instead of using TGB physics which may differ from client-to-client).

I was going to use moveTo and setPositionTarget to move along each point in my path. It sounds like I can use the [snap] option in moveTo to make sure it moves EXACTLY to each point in my path.

My concern is for collisions. Let's say moveTo will cause my projectile to move into my terrain and thus cause a collision. However each client may cause this collision at a slightly different point and this is very, very.

Any idea how I can solve this problem?
#6
03/14/2006 (5:59 am)
Hi John,

I take it your concern is that the same terrain be removed on all clients? Have the server echo back to the clients the exact portion to remove. That should allow them to be in sync with the only real problem being high latency clients. And that has always been a problem for networked games.