#### Archived

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

# weapon question

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

## Recommended Posts

in my first person world, i''m using the following formula to move the camera forward: xPos -= sinf(D3DXToRadian(yRotation)) * .2f; zPos += cosf(D3DXToRadian(yRotation)) * .2f; This works fine, but now i want to include weapons, and i''m going to use the same two statements to move "rockets" forward. but what do i increment/decrement the y Pos with? do i have to check whether the user is "pointing" up or down? or is there a formula that takes care of this? it seems like i would need to take either the cos or sin of the X rotation. thanks! ps -> i used this formula to test, and it kind of works, just wondering if it''s totally off: theObject.xPosWorld -= sinf(D3DXToRadian(theObject.yRot)) * .2f; theObject.yPosWorld += sinf(D3DXToRadian(theObject.xRot)) * .2f; theObject.zPosWorld += cosf(D3DXToRadian(theObject.yRot)) * .2f;

##### Share on other sites
You will be better off in the long run if you start to use matrix operations instead of your current method. As you rmotion becomes more complicated, the matrix method will make more and more sense.

Take a look at the matrix tutorial in the SDK to get started.

##### Share on other sites
maybe i wasn''t clear: i do use matrix operations, but the formula i''ve put in my initial post is in the "arrow up" event, so the user can move forward no matter what direction they are looking. i am using matrix operations to transform objects. sorry about that.

##### Share on other sites
maybe i wasn''t clear: i do use matrix operations, but the formula i''ve put in my initial post is in the "arrow up" event, so the user can move forward no matter what direction they are looking. i am using matrix operations to transform objects. sorry about that.

##### Share on other sites
OK - but I would still say that you might want to use a more matrix based approach.

rotate the user to the walking orientation
translate the user forward along the new forward vector
rotate the user in the view direction

Therefore, to answer your real question: rotate the projectile to the viewer orientation and translate along the new forward vector. This will work for any viewer orientation (up, down right, left, etc)

Edited by - CrazedGenius on January 13, 2002 12:35:33 AM

##### Share on other sites
so after re-positioning the "bullet", i''d only need to increment it''s z axis?

• 32
• 12
• 10
• 9
• 9
• ### Forum Statistics

• Total Topics
631349
• Total Posts
2999473
×

## Important Information

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!