I have a bit of code and need help on figuring out how I can force the character to be “pushed forwards” to counteract them moving backwards while wall climbing.
When climbing, holding W works as the player moves forward and into the wall, and the velocity adds the upward movement.
However, when down-climbing, holding S moves the player backwards away from the wall, making them fall off.
Is there a way I can use LookVector to prevent this?
This is the line that specifically needs to be adjusted, as the Vector3.new allows the character to fall.
elseif s then
anim:AdjustSpeed(.7)
hrp.Velocity = Vector3.new(hrp.Velocity.X, -10, hrp.CFrame.LookVector.Z)
workspace.Gravity = 0
The rest of the code does not have this issue, and allows the player to climb without a problem.
if w then
anim:AdjustSpeed(.7)
if ((wall.CFrame.Y + wall.Size.Y/2) - script.Parent.HumanoidRootPart.CFrame.Y) <= 4 then -- Give a boost to the player's speed to get them over the ledge
hrp.Velocity = Vector3.new(hrp.Velocity.X, 30, hrp.Velocity.Z)
else
hrp.Velocity = Vector3.new(hrp.Velocity.X, 10, hrp.Velocity.Z)
end
workspace.Gravity = 0
if script.Parent.Humanoid:GetState() ~= Enum.HumanoidStateType.Climbing then script.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.Climbing) end
if not anim.IsPlaying then anim:Play() end
elseif s then
anim:AdjustSpeed(.7)
hrp.Velocity = Vector3.new(hrp.Velocity.X, -10, hrp.CFrame.LookVector.Z)
workspace.Gravity = 0
if script.Parent.Humanoid:GetState() ~= Enum.HumanoidStateType.Climbing then script.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.Climbing) end
if not anim.IsPlaying then anim:Play() end
elseif a then
anim:AdjustSpeed(.7)
hrp.Velocity = Vector3.new(hrp.Velocity.X, 0, hrp.Velocity.Z)
workspace.Gravity = 0
if script.Parent.Humanoid:GetState() ~= Enum.HumanoidStateType.Climbing then script.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.Climbing) end
if not anim.IsPlaying then anim:Play() end
elseif d then
anim:AdjustSpeed(.7)
hrp.Velocity = Vector3.new(hrp.Velocity.X, 0, hrp.Velocity.Z)
workspace.Gravity = 0
if script.Parent.Humanoid:GetState() ~= Enum.HumanoidStateType.Climbing then script.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.Climbing) end
if not anim.IsPlaying then anim:Play() end
elseif not w then
hrp.Velocity = Vector3.new(hrp.Velocity.X, 0, hrp.Velocity.Z)
anim:AdjustSpeed(0)
if not anim.IsPlaying then anim:Play() end
end