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?