How would i put a bullet in the right direction?

So I’m making this rifle for a group, I’ve made the bullet and now I need to know if I can use tweenservice/body movers, if so how? I have the ray, mouse.Hit.p and origin.

5 Likes

Tweenservice might be a good option to try out. Me personally I am also making a Bullet system so I might try that or CFrame. I have used Body movers in the past but personally I think it made the bullets look kinda awkward as they would slow down as it approached the target point.

So how would I calculate the time it takes to travel to the destination?

1 Like

With Tweenservice you can control the time it takes to get to it’s destination. With CFrame it would be based on the wait in between each movement along with the distance of each movement.

1 Like

I would change the bullets CFrame to aim it towards mouse.Hit.p:

bullet.CFrame = CFrame.new(bullet.Position, mouse.Hit.p)

Once that is done you would set its velocity so it’ll travel forward:

 bullet.Velocity = 400 -- change to whatever speed you want
2 Likes

To calculate the length of time to get to a destination, you can use the formula distance in studs/speed in studs per second.

I would recommend FastCast, you won’t need any BodyMovers or to use TweenService.

It also has an example gun script, so you can mess around with that.

2 Likes

Thanks a lot! It helped me get really far, the gun almost works.
There’s a problem, all the bullets I fire, including the one in the example gun go straight trough the torso/hrp. They don’t even disappear or something the bullet just ignores the torso/hrp.
Is there a fix for that?

1 Like