Are there any ways to make ballistics more "realistic"?

So recently I made a bullet system (WIP) and well it does work but it barely does on hit registration (it does work, just not as intended)

local handler = {}

local repS = game:GetService("ReplicatedStorage")
local random = Random.new()

function deletePart(P: Part, StgT)
	game:GetService("Debris"):AddItem(P, .01)
end

function bulletHoles(hit: RaycastResult)
	local pos = hit.Position
	local bulletHole = repS.randomstuff.BulletHoles:Clone()
	bulletHole.CFrame = CFrame.new(pos, pos + hit.Normal)
	bulletHole.Parent = workspace
	bulletHole.Anchored = true
	game:GetService("Debris"):AddItem(bulletHole, 5)
end

function ProjectileHit(plr, projectile: Part, properties)
	local hit = workspace:Raycast(projectile.Position, projectile.CFrame.LookVector * properties.fire.velocity * 1.5)
	
	if hit then
		if hit.Instance.Parent:FindFirstChildOfClass("Humanoid") then
			if hit.Instance.Parent ~= plr then
				repS.events.hit:FireServer(hit.Instance, properties.fire.dmg)
			end
			
			deletePart(projectile, .1)
			print("guh2")
		else
			
			bulletHoles(hit)
			
			deletePart(projectile, .1)
			print("guh1")
		end
		
	end
	
	
end

function handler:Fire(plr, origin: Vector3, direction: Mouse, properties)
	
	local bullet = repS.randomstuff.Bullet:Clone()
	bullet.Parent = workspace
	bullet.Anchored = false
	bullet.CFrame = CFrame.new(origin, direction) * CFrame.Angles(random:NextNumber(properties.fire.spread, -properties.fire.spread), random:NextNumber(properties.fire.spread, -properties.fire.spread), random:NextNumber(properties.fire.spread, -properties.fire.spread))
	
	
	local bulletBV = Instance.new("BodyVelocity", bullet)
	bulletBV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	bulletBV.Velocity = bullet.CFrame.LookVector * properties.fire.velocity
	
	ProjectileHit(plr,bullet, properties)
	local loop
		
	loop = game:GetService("RunService").RenderStepped:Connect(function(dt)
		--print( (bullet.Position - origin).Magnitude )
		if (bullet.Position - origin).Magnitude > properties.fire.range then
			deletePart(bullet, .1)
			
			loop:Disconnect()
		end
	end)
	wait()
end

return handler

now I’m a certified idiot at this thing so there are a lot of errors.

Right now are there any further suggestions since I need help:

  1. Better hit registration (if the player/their teammates are hit then the bullet will continue to travel, if it hits the enemy then it will deal damage)

  2. Trail is unseen if it is close (any better ways to make it)

  3. “Realistic” direction (rn I’m using origin, mouse. I need help with origin, worldCFrame kind of stuff)

  4. Optimization. Is there any further optimization I can do?

Gimme Feedback soon fellow devforumers!

1 Like