I have created a jump pad that uses the VectorForce
class, is mass corrected, and takes the player’s current jump power into account. It uses the AssemblyMass
of the HumanoidRootPart for R15 rig types (Or Torso for R6 rig types.) for player mass (which includes any equipped tools and accessories). It takes that mass, divides it by a reference mass (the pal guy player on the local server in Studio), then multiplies it by the JumpVector
value, which is a Vector3
type, from the jump pad part. And since the force is vectored, it doesn’t have to jump straight up. You can send the player off at an angle. The code will determine which part to apply the force to. You can get this from the marketplace here:
I have also include the RBXL file as well.
jumppad.rbxl (37.7 KB)
Server Script
local debounceTime = 1.0
local jumpTime = 1.0
local relation = Enum.ActuatorRelativeTo.World
-- Don't change anything below this line.
local part = script.Parent
local debounce = false
local refMass = 14.155184745788574
local defaultJumpPower = 50
local force = part:GetAttribute("JumpVector")
local sound = part:FindFirstChildOfClass("Sound")
local forceTime = part:GetAttribute("ForceTime")
local magnitude = part:GetAttribute("Magnitude")
if forceTime ~= nil and magnitude ~= nil then
magnitude = nil
warn("ForceTime and Magnitude cannot be specified together. Using ForceTime.")
elseif forceTime == nil and magnitude == nil then
forceTime = jumpTime
end
-- This is used to display the distance between the
-- jump pad and the character when the force is
-- removed.
local function showJumpDist(part, root)
local dist = (part.Position - root.Position).Magnitude
print("Jump Distance:", dist)
end
part.Touched:Connect(function(hit)
local char = hit:FindFirstAncestorOfClass("Model")
local human = char:FindFirstChild("Humanoid")
local root = char:FindFirstChild("HumanoidRootPart")
if root == nil then
root = char:FindFirstChild("Torso")
if root == nil then
warn("Unable to find valid humanoid components.")
return
end
end
if char ~= nil and human ~= nil and not debounce then
debounce = true
-- Create and configure the force vector.
human.UseJumpPower = true
local jump = Instance.new("VectorForce")
local adjForce = defaultJumpPower / human.JumpPower
local adjMass = root.AssemblyMass / refMass
jump.Force = Vector3.new(force.X * adjMass,
force.Y * adjForce * adjMass,
force.Z * adjMass)
jump.Attachment0 = root.RootRigAttachment
jump.ApplyAtCenterOfMass = true
jump.RelativeTo = relation
jump.Parent = root
human.Jump = true
-- Play sound if available
if sound ~= nil then
sound:Play()
end
if forceTime ~= nil then
-- Time to apply force to character.
delay(forceTime, function()
jump:Destroy()
-- Uncomment the line below to show jump distance.
--showJumpDist(part, root)
end)
else
-- A problem was uncovered that due to lag, the ForceTime
-- parameter may not be enough. The Magnitude parameter
-- was introduced as an alternative to deal with this.
-- The idea is that the force is applied until the character
-- has traveled a specific distance from the pad. When that
-- distance is reached, the force is removed.
task.spawn(function()
local partPos = part.Position
local dist = 0
local timer = 10
while dist < magnitude and timer > 0 do
timer -= task.wait()
dist = (root.Position - part.Position).Magnitude
end
jump:Destroy()
end)
end
-- Rate limiting debounce
delay(debounceTime, function()
debounce = false
end)
end
end)
Unlike previous versions, this does not require a client side script to operate. So no remove event is needed. By default, the VectorForce is applied for 1 second, but can be adjusted to suit your needs using various parameters that are attached to the part as attributes.
In testing with game.Workspace.Gravity = 196.2
and the vector force of Y = 3500, I have found that the distance traveled is about 64-65 vertical studs on average. I have seen numbers mostly between 61-69 though, so current server load conditions do play a role in distance traveled. Because of this, this new version includes a Magnitude parameter which will guarantee that the player will travel at least that distance from the jump pad before the force is removed.
Showcase Videos