# Forward/Backward motion [Directx 10][C++]

## Recommended Posts

kirenemook12    103
hello

i want to make the movement in my game so that it moves forward, turns a bit, and moves forward, like a ship

this is my own attempt:

[code]
SpeedZ = 0.2;
SpeedX = tan(angle)*0.2;
{
SpeedZ = -0.2;
SpeedX = tan(angle)*-0.2;
}
{
SpeedZ = 0.2;
SpeedX = tan(angle)*0.2;
}

[/code]

the problem with this is that when it moves along the X-axis, it goes too fast, and if it moves along the Z-axis it goes too slow

##### Share on other sites
Idono87    101
Let me see if i understand. You want your object to have a set speed when it moves forward and turn at the same time?
Meaning that if given enough time it can go around in circles?

##### Share on other sites
kirenemook12    103
[quote name='Idono87' timestamp='1312831043' post='4846316']
Let me see if i understand. You want your object to have a set speed when it moves forward and turn at the same time?
Meaning that if given enough time it can go around in circles?
[/quote]

yes, it should always move in the same direction as its front

##### Share on other sites
kirenemook12    103
always when I have no ideas i find the solution.
I had no idea, so this is the solution that i found, it is working perfect:

[code]

SpeedX = sin(angle)*Speed;
SpeedZ = cos(angle)*Speed;

[/code]

thanks for all your time and effort

##### Share on other sites
Idono87    101
Ah good you found the answer ^^
Sry didnt have time to answer on that earlier.