So i’m making a musket and when I fire the gun, its supposed to make the bullet face the direction of the mouse. It does this well whenever I shoot at the sky, but when I aim at a part and shoot, the bullet turns sideways.
https://gyazo.com/a0b82c06bac9fe430578f5bf78037083
https://gyazo.com/ec9e85cfd07fdae42e4aeace1559f381
im using bullet.CFrame = CFrame.new(bullet.Position, mouse.p) to make it face the mouse
Are you positioning the bullet before you try to do this?
There are 3 potential problems that I can think of:
- Bullet can collide with the end of your gun
- Bullet has incorrect velocity vector
- If you are shooting multiple parts at once, they might collide with each other
No, I position the bullet after I make it face the mouse.
The bullet has cancollide off and is just 1 part. It does aim towards the mouse when I shoot towards the sky, it just turns sideways whenever I am at something other than nil.
Well there’s your problem.
CFrame.new(bullet.Position, mouse.p)
means “from the current position of the bullet, point towards the mouse”. The current position of the bullet is probably random, so your orientation will be too.
Do something like
bullet.CFrame = CFrame.new(gun.Position, mouse.p)
instead
Oh wow. That was the problem and I fixed it, thank you very much.