I am trying to make a cannon but I don't know how to launch the cannonball.
What you could do is utilize BodyMovers to add a velocity to a Part.
BodyVelocity will help you in this case as it applies velocity to a Part at a constant rate. Here's an example of how you could use a BodyVelocity to "launch" a part.
First, you define your BodyVelocity by creating one:
local bodyVelocity = Instance.new("BodyVelocity")
Make sure you define the Part you want to launch as well. Next, parent the BodyVelocity to our Part. This will define the part we want to be affected by the velocity. Also, we will change the MaxForce so our Part can be affected more easily by the body mover.
local bodyVelocity = Instance.new("BodyVelocity") local cannonball = workspace.Cannonball bodyVelocity.MaxForce = Vector3.new(10000, 10000, 10000) bodyVelocity.Parent = cannonball
Now, we set the Velocity property of the BodyVelocity. It is a Vector3, so it will take X, Y, and Z values. We'll use a function to do this.
local bodyVelocity = Instance.new("BodyVelocity") local cannonball = workspace.Cannonball bodyVelocity.MaxForce = Vector3.new(10000, 10000, 10000) bodyVelocity.Parent = cannonball function launch() bodyVelocity.Velocity = Vector3.new(100, 100, 0) wait(2) bodyVelocity.Velocity = Vector3.new(0, 0, 0) end launch()
We now have a function that will apply a force of 100 on the X and Y axis on the part, wait 2 seconds, and then stop applying that force.
If you want more or less force on the ball, you can change the numbers to your liking.
Hope this helps!