Direction of travel
by Jon Jorajuria · in Torque Game Builder · 07/20/2006 (12:05 pm) · 5 replies
Is there an easy way to get an objects direction of travel? Here is what I am trying to do:
get the direction of travel for y (+ or -)
if y = +
$player.setLinearVelocityY(200);
if y = -
$player.setLinearVelocityY(-200);
Obviously this is not the real code, just curious if there is a way to get DOT.
get the direction of travel for y (+ or -)
if y = +
$player.setLinearVelocityY(200);
if y = -
$player.setLinearVelocityY(-200);
Obviously this is not the real code, just curious if there is a way to get DOT.
About the author
#2
Surely the easiet way is:
07/20/2006 (2:52 pm)
The 0,0 point can move depending on how your camera is defined. By default, it's actually in the centre of the screen.Surely the easiet way is:
switch ($player.getLinearVelocityY())
{
case > 0:
$player.setLinearVelocityY(200);
case < 0:
$player.setLinearVelocityY(-200);
}I haven't tested it, but something like that should work.
#3
07/20/2006 (6:20 pm)
Ah, that's a much better method Philip. Looks like it should work.
#4
07/21/2006 (1:52 am)
Just to clarify: positive Y is actually down in TGB. Philip's code still applies, but I thought it was worth mentioning that "if $currentYPosition > $oldYPosition then the object is moving [downwards]". Just as Philip said, "0 0" world coordinates are not technically related to the camera, but the camera's default position (which, just like any other object in TGB, is based on it's center) is "0 0".
#5
07/21/2006 (3:27 pm)
This is the way I went, thank you for pointing me in the right direction:if ( $player.getLinearVelocityY() > 0 )
{
$player.setLinearVelocityY(200);
}
else
{
$player.setLinearVelocityY(-200);
}
Torque Owner Apurva Amin