camera movement..strafing.??

Started by
2 comments, last by AGD011 20 years, 9 months ago
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;
Advertisement
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
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 !
SaM3d!, a cross-platform API for 3d based on SDL and OpenGL.The trouble is that things never get better, they just stay the same, only more so. -- (Terry Pratchett, Eric)
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!

This topic is closed to new replies.

Advertisement