Jumping Mechanics for Obby Game

Hello,
I’m currently creating an obby game in which players walk on a ball:

[:arrow_up:Like that]

player idles
The existing script successfully allows players to walk on the ball “without any issues”, thanks to the implementation of a Vector Force downside to prevent the player and the ball from ascending. However, I have encountered a few challenges related to the jumping mechanics:

Whenever the player jumps, they jump way too high


Furthermore, it goes back to the ground wayyyy too slowly and takes several seconds,
and finally, players can jump infinitely.

I would need the player to jump normally, like if they were jumping from the ground with normal physics.
Here’s the script so far:

local ballRoot = script.Parent
local connection
local cooldown = false

game:GetService("Players").PlayerAdded:Connect(function(plr)
	if ballRoot:FindFirstChild("PlayerWeld") then
		return
	end

	local character = plr.Character or plr.CharacterAdded:Wait()
	local humanoid = character:WaitForChild("Humanoid")

	local humanoidDescription = game:GetService("Players"):GetHumanoidDescriptionFromOutfitId(plr.UserId)
	humanoidDescription.WalkAnimation = "16565961810" 
	-- humanoid:ApplyDescription(humanoidDescription)

	if ballRoot:FindFirstChild("PlayerWeld") then
		return
	end

	local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

	if humanoidRootPart and humanoid then
		-- humanoidRootPart.Anchored = true

		local height = ballRoot.Size.Y / 2 + humanoid.HipHeight + humanoidRootPart.Size.Y / 2 + 3.3
		print(height)
		character:PivotTo(CFrame.new(ballRoot.Position + Vector3.new(0, height, 0)))

		local weld = Instance.new("WeldConstraint")
		weld.Name = "PlayerWeld"
		weld.Part0 = humanoidRootPart
		weld.Part1 = ballRoot
		weld.Parent = ballRoot

		humanoidRootPart.Massless = true
		humanoidRootPart.Anchored = false

		connection = humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
			if not humanoid:GetState(Enum.HumanoidStateType.Jumping) and not cooldown then
				weld:Destroy()
				ballRoot.Prompt.Enabled = true
				cooldown = true
				task.wait(2)
				cooldown = false
			end
		end)
	end
end)

image

I tried to add a cooldown system and to change properties but I can’t figure out a way to fix this. I’d be happy if anyone could help me, thanks! :pray:t2:

1 Like

You may be better off:

  1. Setting the player’s jump power / jump height to 0
  2. Listen for the jump connection, and do :ApplyImpulse on the player.
  3. To detect if they can jump, just check via a raycast if the ball is on the ground or not.

Hello,
thanks for your answer, I set player’s jp to 0 and, instead of using :ApplyImpulse (as it does not seem to work fsr) I’m using a VectorForce whose I change the Force when player jumps/falls. I’m also using raycast.
Small problem: it does not seem like a very reliable solution & it’s not very “natural”, I could tween the position but it doesn’t seem like any good idea…