Introduction to BodyVelocity and LinearVelocity
BodyVelocity
has since been deprecated. LinearVelocity
is an replacement, although you might not know how to use it. BodyVelocity
and LinearVelocity
gives forces to objects. So you can make a bounce pad, or you can just make an automatically moving part. An automatically moving part doesn’t require using a script, but I won’t be covering that in this tutorial.
The LinearVelocity
documentation is located here.
The Attachment
documentation can be located here.
Tutorial
First, create a Script (not LocalScript) into the part you want to turn into a bounce pad.
Write the following code in here:
local JumpPad = script.Parent -- the jump pad you want to select
local JumpSpeed = 0 -- the height of the jump
JumpPad.Touched:Connect(function(hit)
local char = hit.Parent
if game.Players:GetPlayerFromCharacter(char) and char:FindFirstChild("HumanoidRootPart") and not char:FindFirstChild("HumanoidRootPart"):FindFirstChild("LinearVelocity") then
local linear = Instance.new("LinearVelocity")
local attach = Instance.new("Attachment")
linear.Name = "LinearVelocity"
linear.MaxForce = math.huge
linear.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
linear.VectorVelocity = Vector3.new(0, JumpSpeed, 0)
attach.Name = "Attachment"
attach.Position = Vector3.new(0, 1, 0)
linear.Parent = char.HumanoidRootPart
linear.Attachment0 = attach
attach.Parent = char.HumanoidRootPart
wait(0.3)
linear:Destroy()
attach:Destroy()
end
end)
Explaniation
Touched event and getting the player
At the start, we must get the player from the touched event.
JumpPad:Connect(function(hit)
...
end)
Using the game.Players:GetPlayerFromCharacter(hit.Parent)
will get the player that hit it.
We must also check if the player has a HumanoidRootPart
so we can apply forces to it. Using HumanoidRootPart:FindFirstChild("LinearVelocity")
also makes sure we don’t add extra force that we can’t remove.
Adding the jump pad effect
We must create a LinearVelocity
in order to move the player and parent it to the player’s HumanoidRootPart
.
local linear = Instance.new("LinearVelocity")
linear.Name = "LinearVelocity"
linear.MaxForce = math.huge
linear.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
linear.VectorVelocity = Vector3.new(0, JumpSpeed, 0)
This code doesn’t work yet - we’ve chosen the power of how LinearVelocity
works using LinearVelocity.VectorVelocity
and LinearVelocity.VelocityConstraintMode
.
However, it doesn’t mean we’ve chosen the direction yet.
Attachments
Attachments
tell you the direction, which gives you the opportunity to choose the direction for the bounce pad.
local linear = Instance.new("LinearVelocity")
local attach = Instance.new("Attachment")
linear.Name = "LinearVelocity"
linear.MaxForce = math.huge
linear.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
linear.VectorVelocity = Vector3.new(0, JumpSpeed, 0)
attach.Name = "Attachment"
attach.Position = Vector3.new(0, 1, 0)
Now we need to parent the Attachment
and LinearVelocity
, and set the LinearVelocity
to use the attachment.
linear.Parent = char.HumanoidRootPart
linear.Attachment0 = attach
attach.Parent = char.HumanoidRootPart
The delay
If we simply didn’t use Instance:Destroy()
, the player would’ve went on forever.
Let’s add a delay.
wait(0.3)
linear:Destroy()
attach:Destroy()
CONCLUSION
That marks the end of this tutorial. LinearVelocity is basically BodyVelocity, just a little different. Hope you enjoy reading this tutorial. This was my first one, and I put my effort into it.
EDIT: If you change the delay to 0.1
and the jumpspeed to 100
, it’s more smooth. Faster the delay and more the jumpspeed is, the more smooth it gets.