The draft for my weapons system’s internals are complete, though after creating simple raycasting and simulating the bullet line, it hit me that I’m not really too sure how to properly implement the bullet itself.
Any ides are welcome.
While the part I used to simulate the bullet line seems like an effective projectile itself, it’s just a part being tweened to the target position from the barrel using the raycast response information, and calculating speed by distance. This isn’t effective for realistic bullet simulation, and it’s just not efficient enough to be used that way.
simulate it via engine physics, aka actually shoot a block out and use .Touched for hit detection. for replication, just render a beam. if tracers are important, you can replicate the entire block per client, but don’t render it on the server or have the server handle the physics.
use math to simulate the physics (more consistent over networks). like just calculate gravity, the object mass, and then lerp it at the speed of gravitys descent per your gravitational constant, the bullets speed, and the bullets mass.
example:
local grav = Vector3.new(0,-workspace.Gravity,0)
-- returns new bullet CF and new velocity
local function sim(currentCF : CFrame, velocity : Vector3, delta : number)
local newVelo = velocity + gravity * delta
local newPos = currentCF.Position + newVelo * delta
local newLook = newVelo.Unit
local constructedCF = CFrame.new(lookAt, newPos, newPos + newLook)
return constructedCF, newVelo
end
I’m trying to avoid using FastCast, it’s used in one of the popular games i develop for and causes significant issues with optimization, and skilled colleague of mine don’t have a positive opinion about it.
Despite this, I know it’s a well made and useful module, but I’m just not interested in messing with it in general.