So, I’ve been working with this script that makes the player jump when it is touched or jumped on. However, there is a delay when the player touches the pad and when it jumps.
I want the player to jump right when it lands on the jump pad. I haven’t pinned down where it causes this delay. I don’t know if it’s something physics related or something in my script inside the part.
The jump pad becomes increasingly inconsistent (meaning that it won’t jump at all at first touch) when the player jumps off from a height and has increased walk and jump power.
Here is the code and file below: Jump Pad.rbxl (21.4 KB)
local Part = game.Workspace.Part
local toggle = false
Part.Touched:Connect(function(hit)
local partParent = hit.Parent
local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
if toggle == false then
if humanoid then
partParent.Humanoid.Jump = true
toggle = true
local jumpForce = Instance.new("BodyForce")
jumpForce.Parent = partParent.HumanoidRootPart
jumpForce.Force = Vector3.new(0,3000,0)
wait(0.5)
jumpForce:Destroy()
wait(0.2)
toggle = false
end
end
end)
It gets annoying while I’m trying to test my game out, so if anyone has an idea of what might be happening, I would really appreciate it.
A somewhat more consistent resolution (that might be a bit more expensive performance-wise) would be to use magnitude. You can check the distance of the Jump Pad, and if it’s close enough to the player (within 3-5 studs), boost/jump the player.
The nice thing about magnitude is that if used properly– you’d be able to get consistent results, with a lot more control over the situation at hand.
However, what I think would be the most consistent is to use Region3. You’d create a Region3 around the area where the Jump Pad can be activated if the player is within it, run a loop* and check it for the player’s parts. If the player is found, bounce 'em.
*The loop you choose to run can have a major impact on the game’s quality of performance. I’d suggest researching into how specific loops work before deciding on what to do here.
More information on Magnitude can be found here, Region3 information can be found here.
I would reccomend staying away from manually jumping the humanoid. I made a was jump script and the first time I made it, I relied on changing its state to jump it and I noticed a pretty consistent rate at which it would fail. I know it’s not the same system but I think the same would apply to here. A bodyBocity sounds smartest, maybe try messing with it’s D and P settings I believe one I forget with determines the amount of time it takes to get to that velocity.
Ah, finally, something I can help with! I’ve gone through various iterations of this problem and this is the best solution I’ve found:
local defaultJumpPower = humanoid.JumpPower
local jumpMultiplier = 2
-- bind touch event to your part
yourJumpPad.Touched:connect(function(obj)
wait(.1)
humanoid.JumpPower = defaultJumpPower * jumpMultiplier
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
wait(0.25)
humanoid.JumpPower = defaultJumpPower
end)
If you remove the wait(.1) it will create an instantaneous jump, but that feels a little bit weird the 0.1 will let the player slightly walk on to the part a little bit before the jump.
You can also test if the player is in a Enum.HumanoidStateType.Freefall state (vs walking/running) and remove the 0.1 wait and it feels good as an instant bounce effect after a fall.