# Gun movement part 2

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

## 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 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 :)

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
17

• 10
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631420
• Total Posts
2999987
×