When a real cannon is fired, to put it simply, a single large amount of force is applied to the projectile in one single direction (the direction the barrel guides it in). That amount of force is applied once to the projectile, not continually or constantly, which is why the projectile eventually loses its initial energy from the launch (due to friction and gravity), and begins to form an arc. (Parabolic Motion).
Though you don't need to completely replicate how a real cannon fires, there are certain forces in real life that also exist in ROBLOX, like gravity.
You will want to apply the force to your projectile for a very short period of time and then remove the force, this will better simulate a real projectile.
Below are links to two important Wiki Pages that will greatly help you in this matter:
BodyMovers
Gravity
Just how much force should we use? Well, you will want to use a magnitude large enough to counter the force of gravity to a point where the object can become airborne and accelerate through space for a given time before reaching its apex and returning back to its original altitude.
"It is important to note that gravity in ROBLOX is an acceleration, a BodyForce object is a force, and that the BodyForce's force needs to be multiplied by the mass of the object in order to equal the gravitational pull on the object." - ROBLOX Wiki
How do we get the mass of an object? Well, we can simply use the :GetMass() method of a Part.
local MyPart = game.Workspace.Part
local PartsMass = game.Workspace.Part:GetMass()
print(PartsMass)
I would recommend doing something along these lines:
local MyCannonBall = MyCannonBall:Clone()
local force = Instance.new("BodyThrust")
force.Force = Vector3.new(x, y, z)
force.Location = Vector3.new(0,0,0)
MyCannonBall.Anchored = false
MyCannonBall.Transparency = 1
MyCannonBall.Parent = game.Workspace
force.Parent = MyCannonBall
MyCannonBall.Transparency = 0
wait(0.1)
force:Destroy()
It's important to note that, for the above example, you would want to set and rotate the original anchored, transparent projectile in such a fashion that the axis in which the force is applied upon, is angled matching the angle of the barrel.
I hope this helps!
If this answer helped or solved your issue, don't forget to upvote and confirm.
7 comments
What is the "shot" variable for?
Oh yeah... x, y, and z are the position of where the cannonball needs to go and then move, not the amount of force.
Also, I can't find the clone...
The shot variable was a mistake, this is a segment of code from a cannon I made a long time ago - it is fixed No, the (x,y,z) is what local axis of the part that the force will be applied to, not a position.
So, how do I first make my clone go to the (x, y, z) coordinates and then move y + .152 and z - 1?
Hello? I still need help... lol.
The script above is not assigning the position of where the cloned shot will go. The x,y,z coordinates are how much force on each axis will be applied to the shot.