Page 1 of 1

Directional Velocity Problems

PostPosted: Mon Jul 11, 2011 11:42 pm
by code4242
I'm trying to use directional velocity to work my movement system when the player Key Up's a directional key. But when I Key Up, it makes the character move the other way instead of stopping. Any ideas what I'm doing wrong? Also, if anyone has an easier/better way to make a movement system, please mention it.

Code: Select all
if (Boldar.directional_velocity=-12)
{
xvelocity=0;
}


PS. I'm starting the movement with xvelocity=12

Re: Directional Velocity Problems

PostPosted: Tue Jul 12, 2011 1:00 am
by DST
use
if (Boldar.directional_velocity==-12)
{
xvelocity=0;
}

By using only one =, you were setting it to -12. Also, you have mixed directional_velocity with xvelocity?

Best way is to make a use variable, named something like dir.

Then on keydown, you set dir to something.....0 for right, 1 for up,2 for left, and so on. Then in draw actor, you can assign movement based on what value dir is.

You don't really need a keyup, just set dir to 0 at the END of draw actor. Then next frame, if they've got the key down, it will set it to a number again (use repeat on the keydown).

You can say directional_velocity=12; angle=dir*90;