I have a leap mechanic that uses bezier curves and I have a problem where you can no-clip out of bounds if you leap to something that isn’t on the same level as you.
I’ve debugged my code below and realized that this is caused because p0 to p2 is a straight line so I’d like to use raycasts to check if anything is in the way and then adjust the positions accordingly which should just be moving p2 up. To do that I think I just need to see if the ray is inside a part and if it is get the height of that part and change the y value of p2 not sure how to do that though since I suck at math.
local function leap(character : Model, z : number, y : number, travelTime : number)
local root = character:FindFirstChild("HumanoidRootPart")
local humanoid = character:FindFirstChild("Humanoid")
local p0 = root.CFrame
local p2 = p0*CFrame.new(0,20,z) -- added 20 to temporarily fix it
local p1 = p0:lerp(p2,0) * CFrame.new(0,y,0)
local elapsedTime = 0
local connection
connection = RunService.Stepped:Connect(function(time, deltaTime)
elapsedTime = elapsedTime + deltaTime
-- scale by speed factor
local t = elapsedTime / travelTime
local cframe
if t > 1 then -- reached end
onLeapLand()
cframe = p2
connection:Disconnect()
else
cframe = root.CFrame.Rotation + Util:QuadraticBezier(t,p0.Position,p1.Position,p2.Position)
end
root.CFrame = cframe
end)
end