Sign in to follow this  
ravinDavin

Rotate vector by matrix

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
[quote name='ravinDavin' timestamp='1318776877' post='4873129']
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.
[/quote]
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this