How to make a phsyical bullet which follows a raycast path

I want to make a paintball gun where the paintball flies through the air at a set speed and falls down with as a parabolic path. The way I thought of doing it is by raycasting the path that the paintball would follow including the curve downwards and then somehow making a part follow it.

If you have any ideas and/or resources on how to do this sort of thing, please reply! :slight_smile:

You don’t need to define a path for the projectile. Instead, launch the projectile and add a gravity setting that pulls the projectile down. That way, nothing needs to be hard-coded.

1 Like

My concern with this is that Roblox’s physics engine can be buggy and a lot of them flying in the air might cause lag on the server.

That’s right, it can and it will lag and experience heavy latency issues because you shouldn’t be simulating bullet paths on the server.

What you should be doing is simulating the bullets on every client. You can simulate it on the shooter’s client and then fire a server event → which will fire to all other clients, telling them to simulate the bullet as well.

Actual hit detection and motion paths should be handled on the server, for script security. This will prevent exploiting. You don’t need to create a physical part on the server. Instead, create a variable CFrame and edit it every Heartbeat (RunService), firing a raycast from its’ position for hit detection.

2 Likes

You can avoid using actual physics objects by either making your own projectile physics using raycasting or using a module that does it for you like FastCast.
Essentially, use physics equations every Step to update the position of the projectile (factoring in velocity) and the velocity (factoring in acceleration, probably just gravity) and raycasting from the old position to the new.

1 Like

You can do multiple raycasts, using the endpoint of the last ray as the origin of the new ray. Then you adjust the direction to keep gravity in mind, which is something you could calculate with y = -9.81dtdt. As for the parts, you should simulate those on the client, but the rays should be done on the server.

1 Like