Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What do i need to add to a script to give an object momentum when it spawns?

Asked by 4 years ago

I am trying to make a cannon but I don't know how to launch the cannonball.

0
this is not a request site post your script you made so far 3wdo 198 — 4y
0
Like @AlbertoMiAmigo2 said, this isn't a request site. If you want to launch the cannonball though, I'd suggest researching body movers. Trollapse 89 — 4y
0
didn't mean it as a request sorry if it seemed like that and thx tho Hex_0517 10 — 4y
0
hes asking for how to launch it... not for someone to make a cannon for him... @blocktaco EmbeddedHorror 299 — 4y

1 answer

Log in to vote
0
Answered by
megukoo 877 Moderation Voter
4 years ago

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!

Ad

Answer this question