How do you make a projectile with physics?

Hello there!
How can i make a big projectile that the player shoots in the mouse direction and because of gravity it will go down slowly until it hits an object?
I tried using it with curves but it didnt work as i wanted it to.

How can i achieve this?
Any help whould be greatly appreciated!!!

4 Likes

I recommend using the FastCast module for projectile related things.

The FastCast module can be found here.

You can make projectiles with gravity with the module!

4 Likes

Can it work with big projectiles too?

Yep, anything can be made into a projectile

1 Like

You can also look at the Gun Kits by Roblox
You will need most of the functions anyway in the end…

Understand what every line of the code is doing referring to this

Roblox API Reference Manual

and this

https://www.lua.org/manual/5.4/

Then mod the code.

I believe this throws a large object, like a basketball, accounting for the Place’s gravity and mass of object but I forget…

2 Likes

You can use FastCast. But gun physics is easy to code once you understand the formulas and maths.

You can simply use a Step method on the server and use Suvat to calculate the next Position.

If you did mathematics mechanics then you know that Acceleration can be integrated to get Velocity and Velocity to Position.

local Projectile = {
    Acceleration = Vector3.new(0,-workspace.Gravity,0) -- You can add gravity or even wind depending on your needs
    Velocity = Vector3.new(100,0,0) -- Initial velocity of the projectile when fired (code this yourself)
    Position = Vector3.new(0,10,0) -- Starting position of proj
}
function Stepped(runTime, deltaTime)
    Projectile.Position += Projectile.Velocoty * deltaTime -- wrt Time
    Projectile.Velocity += Projectile.Acceleration * deltaTime
    -- You could even have change the acceleration to oush the projectile forward if it is a propelled projectile
    Part.Position = Projectile.Position -- Anchord part
    -- To get collisions you will need to raycast
end

4 Likes