Hello, I came across trying to make a wall climbing system, and wrote a script with some help, but I don’t know how my logic turned out, and I can’t seem to make the orientation right, every frame, the character turns using the “face” variable
Here is a video:
Here is the function:
function onClimb()
local origin = rootpart.Position
local direction = rootpart.CFrame.LookVector
local result = workspace:Raycast(origin, direction, params)
if result then
climbing=true
script.RemoteEvent:FireServer(char.ForceShiftLock, true)
rootpart.CFrame = CFrame.new(rootpart.CFrame.p, Vector3.new(rootpart.Position.X - result.Normal.X, rootpart.Position.Y, rootpart.Position.Z - result.Normal.Z))
face = CFrame.new(result.Position+result.Normal, result.Position)
hum.AutoRotate=false
hum.PlatformStand=true
climbMove.Parent=rootpart
climbGyro.Parent=rootpart
repeat
run.RenderStepped:Wait()
climbGyro.CFrame=face or CFrame.new()
if rootpart.Position.Y > result.Instance.Size.Y then
LedgeClimb()
climbing=false
offClimb()
local ve = Instance.new("BodyVelocity")
ve.MaxForce = Vector3.new(1, 1, 1) * 40000
ve.Velocity = rootpart.CFrame.lookVector * 10 + Vector3.new(0, 7, 0)
ve.Parent = rootpart
game.Debris:AddItem(ve, 0.5)
game.TweenService:Create(ve, TweenInfo.new(0.5, Enum.EasingStyle.Sine), {
Velocity = rootpart.CFrame.lookVector * 10 + Vector3.new(0, 12, 0)
}):Play()
end
local sideOrigin = rootpart.CFrame*CFrame.new(0, -0.4, -1).Position
local sideDirection = rootpart.CFrame.RightVector*(down("D") and -2 or 2)
local hit1 = workspace:Raycast(sideOrigin, sideDirection, params)
local hit2 = nil
if down("D") or down("A") then
if down("D") then
local hit2 = workspace:Raycast(leftArm.CFrame*CFrame.new(-3,0,0).Position,leftArm.CFrame.RightVector*-2,params)
elseif down("A") then
local hit2 = workspace:Raycast(rightArm.CFrame*CFrame.new(3,0,0).Position,rightArm.CFrame.RightVector*2,params)
end
print("Gottem")
end
if (hit1 or hit2) and (down("D") or down("A")) then -- right or left button is down, fires on switch edge
local hit
if hit2 ~= nil then
hit = hit2
else
hit = hit1
end
print(tostring(hit))
local attachment1 = Instance.new("Attachment",hit.Instance)
attachment1.WorldPosition = hit.Position
alignPos.Attachment1 = attachment1
face=CFrame.new(hit.Position+hit.Normal, hit.Position)
game.Debris:AddItem(attachment1,0.005)
end
until (not climbing)
script.RemoteEvent:FireServer(char.ForceShiftLock, false)
hum.AutoRotate=true
hum.PlatformStand=false
end
end