Post revoked due to old and bad scripting
Lazy fix: Add a cooldown to your raycasting after a wall hop.
Actual (attempted) fix:
attachOnWall = function(Part, Int, HitNorm)
local root = char.HumanoidRootPart
wallContactMade = true
root.Anchored = true
local humPosition = Int + HitNorm * HUM_DIST -- This creates a position to place the humanoid. HUM_DIST is how far from the surface the root should be placd
local oldRotation = root.CFrame - root.CFrame.p -- get the rotation of the root.
local newRotation = oldRotation * CFrame.fromAxisAngle(oldRotation.rightVector, math.pi/2)-- rotate the old rotation 90 degrees around the right vector.
local newCF = CFrame.new(humPosition) * newRotation -- Rotates the CFrame
root.CFrame = newCF
end
I’m not sure I totally understand all of the operations you’re applying to the Root, nor am I sure that I’ve done my math correctly. The function does two things:
First it finds the position the Root needs to be in to appear correctly spaced from the surface. Your script already does this fine, and I don’t think I messed up here.
After that, it takes the old rotation of the humanoid, rotates it by 90 degrees, and applies that rotation to the position CFrame to create the rotated CFrame. I’m by no means an expert, but I think this will work.
As I’m writing this now, I’m starting to realize it won’t work if the wall you’re running onto is not perpendicular to the current one, but you might be able to fix that by finding the angle difference between the old surface norm and the new surface normal.
Tldr: It should rotate the HumanoidRootPart around 90 degrees