Skip to main content
gamedev.net
🔒 Locked

weapon question

Started by monkey_face 4 replies 200+ views
Original Post
monkey_face
monkey_face
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;
CrazedGenius
CrazedGenius
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.
monkey_face
monkey_face
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.

monkey_face
monkey_face
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.

CrazedGenius
CrazedGenius
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
monkey_face
monkey_face
so after re-positioning the "bullet", i''d only need to increment it''s z axis?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.