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

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

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
A4L
12
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633767
• Total Posts
3013738
×