Archived

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

AGD011

camera movement..strafing.??

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 this post


Link to post
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 this post


Link to post
Share on other sites