Make Player Stay Upright

Whenever the player hits a wall it “trips” / spins around chaotically. How can I lock the X and Z axis of the Humanoid Root Part’s orientation? I tried using Align Orientation and setting the player’s orientation in a RunService.Stepped loop, but Align Orientation only rotated it in one direction and setting the player’s orientation, for some reason, also set the player’s position.

All help appreciated! :slight_smile:

1 Like

Not exactly sure what you’re asking for but, I would start by making a server script inside of server script service and then you could maybe constantly set the X/Z values in the orientations vector to zero like shown:

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	while true do wait()
		local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
		humanoidRootPart.CFrame.Orientation = Vector3.new(0, humanoidRootPart.CFrame.Orientation.Y, 0)
	end
end)

Haven’t tested, so you can do that and try solve the issue if it doesn’t work…

I’ve already tried that, but it’s very jittery.

i did state that: “Not exactly sure what you’re asking for”

How can I make the X and Z axis of the Player’s orientation constant? That’s what I meant, sorry.

Try this just made it and didn’t test it so far.

Portion of the Code is taken from my previous post of a CFrame rotation method to align Vectors.

--Place in StarterCharacterScripts
	local humanoidRootPart = script.Parent:WaitForChild("HumanoidRootPart")

local randomAxis = Vector3.new(1,0,0) -- Read this in the EgoMoose article

local function getRotationBetween(u, v, axis)
	local dot, uxv = u:Dot(v), u:Cross(v)
	if (dot < -0.99999) then return CFrame.fromAxisAngle(axis, math.pi) end
	return CFrame.new(0, 0, 0, uxv.x, uxv.y, uxv.z, 1 + dot)
end

while true do
humanoidRootPart.CFrame = getRotationBetween(humanoidRootPart.CFrame.UpVector, Vector3.yAxis, randomAxis) * humanoidRootPart.CFrame
	local dt = task.wait()
end

Is there a smoother way to do this? Setting the rotation is very jittery.

I would probably try another faster loop like renderstep or .Stepped if its jittery.

Well, even with render stepped, it’s jittery. Setting the rotation at all is jittery and that’s why I thought of using constraints like Align Orientation, which are smoother. Either there’s no way to do it with Align Orientation, or I just don’t know how to use it. I’m also kinda new to using constraints.

1 Like

Should definitely be possible with align orientation as well.

Try checking out the autorotate module for how I replicated autototate without a humanoid using align orientation and move direction.

Gonna head to sleep now apologies for lack of explanation.

I believe there is a one axis mode for align orientation as well have you tried looking into it? Should be called PrimaryAxis only.

1 Like

I tried the Primary Axis and Secondary Axis, but it doesn’t make much sense. Thanks for your help. I’ll see into it.

1 Like

You’re probably asleep, but for anyone reading this, am I supposed to use this or use a part of this? In the post, it uses Align Orientation, but I still don’t understand how it works. Can anyone explain?

Put in renderstepped:

HumanoidRootPart.CFrame = CFrame.lookAt(HumanoidRootPart.CFrame.Position, HumanoidRootPart.CFrame.Position + HumanoidRootPart.CFrame.UpVector)

I’m assuming you know how to make a renderstepped loop and assign HumanoidRootPart.

Already tried

I think you forgot to disable Humanoid.AutoRotate then.

That doesn’t seem to do anything.

In that case, make it .Stepped instead of .RenderStepped so that it fires when the humanoid does its physics.

No loop where it sets the orientation works. Is there any way to make it smooth using Align Orientation? I was thinking it had to do with Primary Axis and Secondary Axis, but I don’t understand how it works. You have any ideas?

I don’t think it’s possible to limit the axis of AlignOrientation.

You can try increasing the mass of the character’s root part and then disabling the falling down state.

To combat this issue in Claw In The Chamber I used a method where you disable all Humanoid state types related to Ragdolls.

I never experienced Players falling over, or flopping to get back up on their feet. Instead whenever they hit an object hard the wall pushes them back a bit and does not cause a ragdoll. They always are upright on their feet.

Basically what @SubtotalAnt8185 said but hopefully the extra details help.