Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you manually rotate a humanoid?

How do you manually rotate a humanoid? I'm trying to lock my player's walking directions to 2 main axis (forward/backwards, side to side). Not entirely sure how to go about it. Would love input!

1 answer

I assume your looking for your player to move on a 2D Plane This script limits the player to only be able to move on 2 Axis. Key components are Object Mass, Body Position, and Vector3

function GetMass(object)
	local mass = 0
	if pcall(function() return object:GetMass() end) then
		mass = object:GetMass()
	end
	for _,child in pairs(object:GetChildren()) do
		mass = mass + GetMass(child)
	end
	return mass
end

function onPlayerRespawned(newPlayer)
	wait()
	local torso = newPlayer.Character.Torso 
	local bp = Instance.new("BodyPosition")
	bp.Name = "TwoD"
	bp.position = torso.Position
	bp.P = 1000000
	bp.D = 1000
	bp.maxForce = Vector3.new(0, 0, 1000000)
	bp.Parent = torso
	local bf = Instance.new("BodyForce")
	bf.force = Vector3.new(0, 100*GetMass(newPlayer.Character), 0)
	bf.Parent = torso
	newPlayer.Character.Humanoid.WalkSpeed = 24
	script.LocalScript:Clone().Parent = torso.Parent
	newPlayer.Character.DescendantAdded:connect(function()
		bf.force = Vector3.new(0, 100*GetMass(newPlayer.Character), 0)
	end)
	newPlayer.Character.DescendantRemoving:connect(function()
		bf.force = Vector3.new(0, 100*GetMass(newPlayer.Character), 0)
	end)
end

function onPlayerEntered(newPlayer)
	if newPlayer.Character then
		onPlayerRespawned(newPlayer)
	end
	newPlayer.Changed:connect(function (property)
		if (property == "Character") and newPlayer.Character then
			onPlayerRespawned(newPlayer)
		end
	end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

1 comment

0

Not exactly. I basically want to player to only be able to walk 0, 90, 180, 270

This discussion is preserved as it was. New answers, comments, and votes are closed.