# Rotate vector by matrix

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

## 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 on other sites

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

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 18
• 36
• 9
• 16
• 75