# QuestionFixing movement after changing angles in usercmd

#### norgor

##### Newbie
Full Member
When i change angles in usercmd the player walks the wrong way, which makes 100% sense.
I've been asking lots of people, but i couldn't find anything. Therefore im asking you guys...
How do i calculate the forwardmove and sidemove to be correct after i changed the angles?

Right now this is my code, but it doesnt work.
C++:
``````		//Old angles and movement
Vector oldviewangles = pCmd->viewangles;
float oldsidemove = pCmd->sidemove;
float oldforwardmove = pCmd->forwardmove;
float oldupmove = pCmd->upmove;

Vector aimangles = aimat(0.0f,0.0f,0.0f);

pCmd->viewangles.X = aimangles.X;
pCmd->viewangles.Y = aimangles.Y;
pCmd->viewangles.Z = aimangles.Z;

float delta = pCmd->viewangles.Y - oldviewangles.Y;

pCmd->forwardmove = (sin(delta * (M_PI / 180.0f)) * oldforwardmove) + (cos(delta* (M_PI / 180.0f)) * oldsidemove);
pCmd->sidemove = (cos(delta * (M_PI / 180.0f)) * oldforwardmove) - (sin(delta * (M_PI / 180.0f)) * oldsidemove);``````
All help will be greatly appreciated!

Last edited:

#### NTvalk

##### Hacker
Meme Tier VIP
Hey what game is this.
When i did this I had to make sure the angles dont get too high. Otherwise i also had random behaviour.

#### norgor

##### Newbie
Full Member
The game is csgo and the angles don't get above 360 degrees

#### norgor

##### Newbie
Full Member
Isnt it 180 max angle? and -180 min?
for X axis ^
and for Y axis is 89 -89
Fixed that, but it still doesnt work.
PS. 89 isn't the max angle for Y axis, if you go above it just turns the view upside-down. Which is actually perfectly fine. All angles are -180.0f to 180.0f if you go above that they just subtract 360.0f from it. So you basically start at -180.0f again.

Last edited:

#### norgor

##### Newbie
Full Member
Anyone? D:

Attention! Before you post:

99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

• Fill out the form correctly
• Tell us the game name & coding language