Jump to content
  • Advertisement

Archived

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

AGD011

camera movement..strafing.??

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

If you intended to correct an error in the post then please contact us.

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

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
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!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!