If Functions
by Gino Ferrand · in Torque Game Builder · 09/30/2008 (4:15 pm) · 3 replies
Hi,
I'm trying to get my character to move, but I want the correct animation to go along with it.
If you press the "d" key then he moves right and the correct animation moves his legs at the same time but if you press another key at the same time and let go off the first key then the animation stops. Is there any way I can add a function where it simply detects my character's velocity on the x-asix. On the most basic level i guess it would look something like this.
if(LinearVelocityX == 0)
{
$pGuy.setAnimation("PlayerStand");
}
else
{
$pGuy.setAnimation("PlayerRun");
}
Does this look correct at all??
Help please. Thanks
I'm trying to get my character to move, but I want the correct animation to go along with it.
If you press the "d" key then he moves right and the correct animation moves his legs at the same time but if you press another key at the same time and let go off the first key then the animation stops. Is there any way I can add a function where it simply detects my character's velocity on the x-asix. On the most basic level i guess it would look something like this.
if(LinearVelocityX == 0)
{
$pGuy.setAnimation("PlayerStand");
}
else
{
$pGuy.setAnimation("PlayerRun");
}
Does this look correct at all??
Help please. Thanks
#2
Yea it did work. The problem is that when i press the "a" key he moves left perfectly fine but if at the same time I hold the "w" key to move upwards and then let go off the "A" key then the stop animation comes on. Even though he is still moving so really the animtion should still be effective. It's hard to explain, but it seems like the StopAnimation function from letting go off the first key overrides the second key's function for movement, if that makes sense.
10/01/2008 (10:54 am)
Hey Houssen, Yea it did work. The problem is that when i press the "a" key he moves left perfectly fine but if at the same time I hold the "w" key to move upwards and then let go off the "A" key then the stop animation comes on. Even though he is still moving so really the animtion should still be effective. It's hard to explain, but it seems like the StopAnimation function from letting go off the first key overrides the second key's function for movement, if that makes sense.
#3
10/01/2008 (5:48 pm)
I know this problem, you need to use the update movement function which is mentions in the my fish game tutorial.
Sam.E
function Guy::onLevelLoaded(%this, %scenegraph) { $Guy = $this; moveMap.bindCmd(keyboard, "a", "MoveLeft();", "StopLeft();"); } function MoveLeft() { $Guy.setLinearVelocityX(-15); $Guy.setAnimation("GuyLeftMovingAnimation"); } function StopLeft() { $Guy.setLinearVelocityX(0); $Guy.setAnimation("GuyLeftStandingAnimation"); }Obviously this is only the left animation and movement of the code but you should know how to make it into right and up/down. I hope this helps you :).