Archived

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

getting a 3D model to work in fps game

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

I am working on my first FPS game and am trying to get a 3D weapon to follow the player around. I have been trying to use the following variables that are part of my camera to calculate the position and rotation of the weapon. These variables are: //Stores the up vector of the player D3DXVECTOR3 m_up; //Stores the viewings vector to show direction D3DXVECTOR3 m_look; //Stores the right vector to show direction D3DXVECTOR3 m_right; //Stores the position of the player D3DXVECTOR3 m_position; I have managed to get the weapon to rotate slightly, but it simply does not move far enough. I would be very grateful for any suggestions and help. thanks in advance

Share this post


Link to post
Share on other sites
Set the weapon position to be a combination of the player''s m_look vector (scaled to be in-front of the player), then scale the m_up and m_right vectors to offset the weapon. Finally add the player position to the weapon.

Ant

Share this post


Link to post
Share on other sites
I have managed to scale m_look,m_up and m_right so the weapon is in the correct position when I look straight ahead, but when I rotate the player the weapon only moves in a diagonal straight line, it does not follow the rotation of the player. if any one can help me fix this problem I would appreciate the help

thanks in advance

Share this post


Link to post
Share on other sites
you need to get the At, right and up vectors of the player. Lets say the player is pointing in the Z direction, so the result would be a 3D vector indicating the players forward direction (''At vector'') i.e. { 0.f, 0.f, 1.f }.

The up direction is Y so ... { 0.f, 1.f, 0.f }.

And the right direction is X ....{ -1.f, 0.f, 0.f }.
Ignore the fact that X is -1 rather than +1 as this depends on the co-ordinate system.

You get these values from the matrix for the player. You can then scale these values to get a position offset from the player''s position, for your weapon.

Finally, set the weapon''s at, up and right vectors to be the same as the player''s.

Share this post


Link to post
Share on other sites