I have a vaulting script that allows you to vault over bricks, but when I vault over things, the momentum from my running isn’t saved and I slowdown just to vault on the brick. Here’s my code and a video example.
local plr = game:GetService("Players").LocalPlayer
local mse = plr:GetMouse()
repeat wait() until plr.Character
local char = plr.Character
local hrp = char:WaitForChild("HumanoidRootPart")
local hum = char:WaitForChild("Humanoid")
function detectWall()
local lv = hrp.CFrame.lookVector
local ray = Ray.new(hrp.CFrame.p, ((hrp.CFrame.p + lv) - hrp.CFrame.p).unit * 1.5)
local hit,pos = workspace:FindPartOnRay(ray,char)
if hit and hit:IsA("BasePart") then
return hit, lv
end
end
function checkUnder()
local ray = Ray.new(hrp.CFrame.p, ((hrp.CFrame.p + Vector3.new(0,-3.1,0) - hrp.CFrame.p)))
local hit,pos = workspace:FindPartOnRay(ray, char)
if not hit then
return true
end
end
function components(pt, vec)
local cf = pt.CFrame
local vectors = {}
local smallest = math.huge --// neat hack
local chosen
local x, y, z, m11, m12, m13, m21, m22, m23, m31, m32, m33 = cf:components()
local v1 = Vector3.new(m11, m21, m31)
local v2 = Vector3.new(m12, m22, m32)
local v3 = Vector3.new(m13, m23, m33)
local v12 = -Vector3.new(m11, m21, m31)
local v22 = -Vector3.new(m12, m22, m32)
local v32 = -Vector3.new(m13, m23, m33)
vectors = {v1, v2, v3, v12, v22, v32}
for i, v in pairs(vectors) do
local dotv = 1 - (v:Dot(vec))
if dotv < smallest then
smallest = dotv
chosen = v
end
end
return -chosen
end
function createBV(vec)
local bv = Instance.new("BodyVelocity", hrp)
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = vec
return bv
end
function climbWall(prt, vec)
local yClimb = prt.CFrame.p.Y + prt.Size.Y/2
local yHRP = hrp.CFrame.p.Y
local yDist = math.abs(yClimb - yHRP)
print(yDist)
if yDist <= 3 then
spawn(function()
local bv = createBV(Vector3.new(0,15,0))
game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Animation):Play()
wait(.25)
bv.Velocity = Vector3.new(0,0,0) + vec*5
game.Debris:AddItem(bv, 0.2)
end)
return true
end
return false
end
mse.KeyDown:connect(function(key)
if key == " " and checkUnder() == true then
local part,lookvec = detectWall()
if part then
local frontVec = components(part, lookvec)
local pos1 = part.CFrame.p + frontVec*part.Size.X/2
local pos2 = part.CFrame.p + frontVec*part.Size.Z/2
local pos1m = (pos1 - hrp.CFrame.p).magnitude
local pos2m = (pos2 - hrp.CFrame.p).magnitude
if climbWall(part, -frontVec) == true then
return
end
end
end
end)