Archived

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

monkey_face

weapon question

Recommended Posts

monkey_face    122
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 this post


Link to post
Share on other sites
CrazedGenius    156
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 this post


Link to post
Share on other sites
monkey_face    122
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 this post


Link to post
Share on other sites
monkey_face    122
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 this post


Link to post
Share on other sites
CrazedGenius    156
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 this post


Link to post
Share on other sites