#### Archived

This topic is now archived and is closed to further replies.

# camera movement..strafing.??

This topic is 5617 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello. I''m using some camera movement based on NEHE''s tutorial # 10. The code moves forward and backwards fine, but I can''t figure out how to get it to correctly strafe left and right. Currently it will strafe left and right when lookrightleft = 0 or 180 degrees. at 90 and 270, when I push left it goes right, and when I push right it goes left. when lookrightleft = 45 or 135 it goes up and down not left or right. any help or advice is greatly appreciated! //This code moves forward xpos += (float)sin(-lookrightleft*piover180) * 0.1f; ypos += (float)cos(-lookrightleft*piover180) * 0.1f; // This code moves backwards xpos -= (float)sin(-lookrightleft*piover180) * 0.1f; ypos -= (float)cos(-lookrightleft*piover180) * 0.1f; // This code I thought should strafe left ypos += (float)sin(-lookrightleft*piover180) * 0.1f; xpos += (float)cos(-lookrightleft*piover180) * 0.1f; // This code I thought should strafe right ypos -= (float)sin(-lookrightleft*piover180) * 0.1f; xpos -= (float)cos(-lookrightleft*piover180) * 0.1f;

##### Share on other sites
Use the working code for moving forward, except add or subtract 90 degrees from the angle. By the way, math lib has DEGTORAD() and RADTODEG() to take care of that pi/180 stuff.

Mop

##### Share on other sites
It''s easy to find a left/right vector if you have a forward/backward vector.

Say a forward/backward vector is (x, 0, y), a left/right vector
will be (-y, 0, x). You''ll have to tune depending on the space orientation. (I assumed the (0, 1, 0) vector points up, which is the default for OpenGL IIRC).

So if you have a correct way for moving forward, you''ll have no problem creating a correct strafe movement.

Hope it helps !

##### Share on other sites
Awesome! thank you both very much! I thought it should be easy, but I kept getting confused with wrong results. thank you both very much!

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 9
• 20
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633383
• Total Posts
3011583
• ### Who's Online (See full list)

There are no registered users currently online

×