Jump to content
  • Advertisement
Sign in to follow this  
ravinDavin

Rotate vector by matrix

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

Hi, I have a gun which rotates as I move my mouse and shoots bullets whichs go the right direction and the same angle as the gun. My problem is I want the bullets to start at the top of the gun. I thought I would just have to multiply a vector that was set at the tip of my gun in the default direction and transform is with the same rotation matrix I used for the gun. It failed miserably.

Share this post


Link to post
Share on other sites
Advertisement

Hi, I have a gun which rotates as I move my mouse and shoots bullets whichs go the right direction and the same angle as the gun. My problem is I want the bullets to start at the top of the gun. I thought I would just have to multiply a vector that was set at the tip of my gun in the default direction and transform is with the same rotation matrix I used for the gun. It failed miserably.

2D or 3D ?

Try this(Assuming 2D):
-get the center position of the gun(Average of all vertexes)
-then set a radius that just barely overlaps the gun.
-Then use the angle that you rotated the gun by and then use these functions to find the initial position vector for Each Bullet:
Initial_Bullet_POS_X = (cos(AngleOfGun)*SetRadius) + CenterPos.X;
Initial_Bullet_POS_Y = (sin(AngleOfGun)*SetRadius) + CenterPos.Y;
This should work in 2D.

or you could do this (pretty much the same method but without knowledge of angles):
-Subtract Mouse Position vector by the Center Vector of the Gun
-Normalize the Difference of those vectors
-Scale the normalized Vector by the radius
-Add the CenterPosition to the scaled Vector

Share this post


Link to post
Share on other sites
Hi, zombies and zombie lovers..
To make the bullets start at the top of the gun is a translation - before rotation !! its an offset in the body's construction space.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!