Sorry for the weird title, wasn’t really sure how to describe it properly.
Basically I’m working on making a wall jump system which is generally going well but I’m not sure how I would go about handling if the player hits the wall close to the corner. I have an idea in mind but I’m not sure how to calculate it or angle the player accordingly if that makes sense.
So basically how it works is that the player is to jump into a wall, a ray is casted from their humanoid root part, if the ray hits the wall, the player will stick to the wall and will be able to jump off, they’d be sent in the direction of their HumanoidRootPart’s LookVector, replicating a jump. So far so good, no issues so far with that.
The issue is if they hit a corner, I don’t want them to stick to whatever face is closest, I want to create a rounded corner effect.
Basically what I was thinking is to split each corner into parts, check what corner they hit if any, and angle them accordingly, probably lerping between each face’s angle depending on how far they are from either corner like this:
Then, if they hit at the orange here, angle the humanoid root part at that position but angle the character 25% between the blue and green faces
What I’m unsure of:
How do I determine how far the player is from the corner, if any?
How do I determine at what angle to angle the player?
That just places a part at the corner of a part. I’m looking to angle the character away from the wall at a certain angle depending on how far away they are from a corner.
I was overcomplicating it. I just have to check the magnitude from each corner, determine which corner the player is closest to, and look away from the corner from the HRP’s position (negative lookVector)
local function angleAroundPart(humanoidRootPart: BasePart, rayPos: Vector3, rayNormal: Vector3, partToPivot: BasePart)
local bottomLeft = partToPivot.CFrame * CFrame.new(-partToPivot.Size.X / 2, 0, -partToPivot.Size.Z / 2) -- - -
local bottomRight = partToPivot.CFrame * CFrame.new(partToPivot.Size.X / 2, 0, -partToPivot.Size.Z / 2) -- + -
local topLeft = partToPivot.CFrame * CFrame.new(-partToPivot.Size.X / 2, 0, partToPivot.Size.Z / 2) -- - +
local topRight = partToPivot.CFrame * CFrame.new(-partToPivot.Size.X / 2, 0, partToPivot.Size.Z / 2) -- + +
local corners = {bottomLeft; bottomRight; topLeft; topRight}
local closest, closestNumber = nil, math.huge
for i,v in ipairs(corners) do
local currentMagnitude = (v.Position * Vector3.new(1,0,1) - rayPos * Vector3.new(1,0,1)).Magnitude
if currentMagnitude < closestNumber then
closest = v
closestNumber = currentMagnitude
end
end
if closest and closestNumber < cornerThreshold then
humanoidRootPart.CFrame = CFrame.lookAt(
rayPos,
humanoidRootPart.Position - CFrame.lookAt(
humanoidRootPart.Position,
Vector3.new(
closest.Position.X,
humanoidRootPart.Position.Y,
closest.Position.Z)
).LookVector * 5) * CFrame.new(0, 0, -humanoidRootPart.Size.Z / 2)
else
humanoidRootPart.CFrame = CFrame.lookAt(rayPos, rayPos + rayNormal) * CFrame.new(0, 0, -humanoidRootPart.Size.Z / 2)
end
end