Sign in to follow this  

Gun movement part 2

This topic is 4336 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

Heyos. I'm trying to get my gun to follow my FPS camera properly. I've got it following the rotation around the y-axis to work fine. But I can't get the gun to follow when I look up/down rotating around the x-axis (ie-looking up towards sky and looking down towards ground). Here's the lookat vector that I'm using, which should be right:
	float lookatX = eyePt.x + cosf( m_player.GetRotAngleX() ) * sinf( m_player.GetRotAngleY() );
	float lookatY = eyePt.y + sinf( m_player.GetRotAngleX() );
	float lookatZ = eyePt.z + cosf( m_player.GetRotAngleX() ) * cosf( m_player.GetRotAngleY() );
	D3DXVECTOR3 lookatPt( lookatX, lookatY, lookatZ );

Now, to position my weapon, first I set the weapon's y angle rotation to whatever the player's y rotation angle is. Also I set the weapon's position to the player's position with a little offset to get it into view. This works fine. The gun follows as I rotate left and right. I'm pretty sure I _don't_ need to set the x rotation angle of the weapon, since I don't want the weapon to rotate around iteself. I just want it to "move" with the player as he is looking towards the sun or toward the ground. Obviously, there's something I'm not doing because as I look up/down with the camera the gun just sits there and doesn't follow along. Any suggestions?

Share this post


Link to post
Share on other sites
Oi, did it way easier! Basically I just rendered it with a fresh camera after rendering all my other crap. I set the eye point to 0, 0, -1.5, the look at pt to 0, 0, 1 and the gun's position to 0, 0, 0 and it renders perfectly and stays in position regardless if I rotate or not. Very happy :)

Share this post


Link to post
Share on other sites

This topic is 4336 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this