Parkour system help

local UIS = game:GetService(“UserInputService”)
local TweenService = game:GetService(“TweenService”)
local Character = script.Parent
local Root = Character:WaitForChild(“HumanoidRootPart”)
local Humanoid = Character:WaitForChild(“Humanoid”)

– Vault animation setup
local VaultAnimation = Instance.new(“Animation”)
VaultAnimation.AnimationId = “rbxassetid://128897073877701” – Replace with your animation ID
local VaultAnimTrack = Humanoid:LoadAnimation(VaultAnimation)

– Raycast parameters
local Params = RaycastParams.new()
Params.RespectCanCollide = true
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.FilterDescendantsInstances = {Character, workspace.CurrentCamera}

– Vault ranges
local VaultCastRange = 5
local VaultCastHeightRange = 3.5

– Perform vault with smooth motion
local function performVault(obstacle, isBoosted)
obstacle.CanCollide = false – Temporarily disable collision

-- Ensure vault animation is loaded and play it
if VaultAnimTrack then
	VaultAnimTrack:Play()
else
	warn("Vault animation failed to load.")
	return
end

local obstacleHeight = obstacle.Size.Y
local upwardOffset = obstacleHeight + 1.5 -- Adjust to clear the obstacle just enough
local horizontalDistance = 4 -- Increased horizontal distance for more complete vault

-- Calculate mid and end positions
local midPosition = Vector3.new(
	obstacle.Position.X,
	obstacle.Position.Y + upwardOffset, -- Clear the obstacle properly
	obstacle.Position.Z
)
local endPosition = midPosition + Root.CFrame.LookVector * horizontalDistance

-- Smooth vault trajectory using `TweenService`
local midTweenInfo = TweenInfo.new(
	0.2, -- Adjusted for a smoother and more complete movement
	Enum.EasingStyle.Sine, -- Smooth in-out motion
	Enum.EasingDirection.Out
)
local endTweenInfo = TweenInfo.new(
	0.2, -- Adjusted for a smooth transition back to the ground
	Enum.EasingStyle.Sine, -- Smooth in-out motion
	Enum.EasingDirection.In
)

-- Tween to mid position (over the obstacle)
local midTween = TweenService:Create(Root, midTweenInfo, {CFrame = CFrame.new(midPosition, midPosition + Root.CFrame.LookVector)})
midTween:Play()
midTween.Completed:Wait() -- Wait for mid position to complete before moving to next step

-- Tween to final position (smooth landing)
local endTween = TweenService:Create(Root, endTweenInfo, {CFrame = CFrame.new(endPosition, endPosition + Root.CFrame.LookVector)})
endTween:Play()
endTween.Completed:Wait() -- Wait for the final position before stopping

-- Stop the vault animation after motion completes
VaultAnimTrack:Stop()
obstacle.CanCollide = true -- Restore collision after vault
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true) -- Enable jumping after vault

end

– Jump request event
UIS.JumpRequest:Connect(function()
if Humanoid.FloorMaterial == Enum.Material.Air then return end

local headPosition = Character.Head.CFrame.Position + Vector3.new(0, 1.5, 0)
local VaultCast = workspace:Raycast(Root.CFrame.Position, Root.CFrame.LookVector * VaultCastRange, Params)
local VaultCastHead = workspace:Raycast(headPosition, Root.CFrame.LookVector * VaultCastHeightRange, Params)

-- If no obstacle or if obstacle is too high, perform normal jump
if VaultCastHead or not VaultCast then
	Humanoid:ChangeState(Enum.HumanoidStateType.Jumping) -- Normal jump if no obstacle
	return
end

Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false) -- Temporarily disable jumping for vault

local obstacle = VaultCast.Instance
local isBoosted = obstacle:GetAttribute("VaultBoost") or false
performVault(obstacle, isBoosted)

end)

trying to make it more smooth and realistic, what can i do?

1 Like

Uhh why is this AI generated and why are you using tweens? I used BodyVelocity for my self and it worked out perfect normally I wouldnt give a code snippet since this is ai generated but anyways here is the one I used for vaulting

	local Vel = Instance.new("BodyVelocity")
	Vel.Parent = self.HumanoidRootPart
	Vel.Velocity = self.HumanoidRootPart.CFrame.LookVector * 20 + Vector3.new(0, 10, 0)
	Vel.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	game.Debris:AddItem(Vel, 0.15)
3 Likes

thank you for responding! i used chatgpt for most of this code because nothing i was doing worked, where would i insert this code? thank you

its not a fully code its just a function for the vaulting velocity. You need to insert this inside your Userinputservice keypress event