Jump to content
  • Advertisement
Sign in to follow this  


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

im current trying to implement a bullet being fired from the position of the player, at the moment im simply using Transform = translation * rotation; such that when the bullet is fired, it increments in z, by a velocityZ, and then rotates by the players rotation, (360degs being a full spin). but this obviously only works while the player is at 0,0,0 pos, as the y rotation is gonna be always applied on the 0,0,0 axis.
if (this->alive == true)	//if the current bullet is alive, then update
		D3DXMATRIX translation;
		D3DXMATRIX scale;
		D3DXMATRIX rotation;
		D3DXMatrixTranslation(&translation, pos.x, pos.y, pos.z += velocityZ);      //pos equals the position that bullet was fired, and stays at this value, until fired again, where a new position is added
		D3DXMatrixRotationY(&rotation, rot.y);

		//Transform =  rotation * translation;
		Transform =  translation * rotation;
so, how would i rotate the bullet, in Y, but on the bullets initial position?

Share this post

Link to post
Share on other sites
D3D uses row vectors, so
translation * rotation
means to translate the bullet and to rotate the translated bullet. However, looking at the matrix math, this means not only to change the orientation of the bullet but also its position. So, what you want to do is
rotation * translation
instead. This changes the orientation and translates the rotated bullet to its target position.

You should decouple the bullet from the shooter when the bullet gets instantiated. I.e. set its initial position (i.e. translation in world co-ordinates) to that of the shooter, and set its velocity also in world co-ordinates.

Share this post

Link to post
Share on other sites
ok cheers, i was thinking about it kinda wrong, i was hoping to just translate in z, but while the bullet is rotated, thus it moving in x an z.

so, with the way you suggested, im gonna have to apply the veclocity to both x and z position, i guess incorporating the bullets initial yrotation when fired.

hmm, i'll have to work that out

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!