Best way to do physics based bullets instead of ray-casted?

I have been trying to do bullet drop for a while and I had an idea yesterday to just spawn a part and use a BodyForce to move the part as if it was a bullet. I figured since this runs with the physics engine inside Roblox it may be less intense than casting tons of rays for bullet drop. I coded this in this morning but I realized the outcome was inconsistent, but the data I input is consistent every time.

See how the bullet lands at a different place every other time.
https://gyazo.com/1929480f12d7f359b2055de1c5befe72

Heres my code, its currently in a server script because I was just testing.

local Bullet = Instance.new("Part")
Bullet.Name = "Bullet"
Bullet.Anchored = false
Bullet.CanCollide = false
Bullet.Material = Enum.Material.Neon
Bullet.Size = Vector3.new(.2, .2, 2)
Bullet.CFrame = CFrame.new(workspace.BulletSpawn.Position, workspace.BulletSpawn.Position + workspace.BulletSpawn.CFrame.LookVector)
Bullet.Parent = workspace
	
Bullet:SetNetworkOwner(Players:GetPlayerByUserId(14112295))
	
local BulletCollisionEvent = Bullet.Touched:Connect(function(TouchedPart)
	if TouchedPart ~= workspace.BulletSpawn then
		Bullet:Destroy()
	end
end)
	
local BulletForce = Instance.new("BodyForce")
BulletForce.Force = Vector3.new(0, 50, -100)
BulletForce.Parent = Bullet
	
DebrisService:AddItem(BulletForce, .1)
	
wait(1)

If anyone has ever done a physics based bullet system and has any info, please let me know :slight_smile:

Just a heads up, a physics / part based system for a bullet is possibly more prone to being hacked more easily since you give physics ownership of the bullet to the player. This could mean that it would be quite easy to modify.

Alternatively, there is a library called FastCast which may be a better option, since it simulates a physics based system while still using raycasting - basically makes it much harder to hack (I’m mainly referring to script kiddies since often times they are the majority of hackers you find).

2 Likes

To do ‘bullet drop’ with raycast, you simply just create a series of rays. Attached is a picture.

Ontop is a single ray. The second one is a series of rays created, with each subsequent one angled downwards, as gravity would cause the path to droop.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.