I need help making efficient and effective bullets for my gun system

Hi!

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.

Thanks for reading!

If you are looking for realism without spending time and effort into a system you could try FastCast

ur options assuming ur going for realism:

  1. 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.

  2. 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
2 Likes

Hi, I did something similar on one of my really old (2020) gun system draft


though the way i had implemented it here sucks :sob:

I’ll look into creating something like this for my system and get back to you, thanks for the example of a better way to do this.

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.

Thanks for the suggestion though!

1 Like

Hey!

Do you think you could provide a more demonstrative example? I.E an example model or something?

My minds hitting a blank here. Usually when that happens, I end up just scrapping the project, and I really don’t wanna do that :frowning:

Thanks.

(Edit: fixed typos)