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

How do I make my character face my mouse?

Using the code below once works, but if I tried to put it in a while loop, it won't work and instead look like I'm having a seizure. I understand why it won't work, the humanoid is trying to always keep you upright. But, how do I fix that?

character.HumanoidRootPart.CFrame = CFrame.new(character.HumanoidRootPart.Position,hit.Position)

This is what I want to happen: https://gyazo.com/e1e09fce8f1fcdb8a155b9a6125e53a2

2 answers

Try using BodyGyros as it makes the transition much smoother. Also when you use Cframes for HumanoidRootPart it makes the reaction a lot choppy simply add a vector3.

Make sure this is in a local script in player < startercharacters

BodyGyro.CFrame = CFrame.new(HumanoidRootPart.Position, Vector3.new(mouse.Hit.p.X, HumanoidRootPart.Position.Y, mouse.Hit.p.Z)) 

8 comments

0

What exactly is pp?

0

Pp refers to the characters primary root part

0

would it be the Humanoid.RootPart? Just to clarify

0

Yes.

0

I tried it, I put the code in a local script in StartCharacterScripts, but it doesn't work. i replaced p as position and made pp as a variable to humanoid.rootpart. Nothing happend.

0

Try publishing nothing seems wrong with this code

0

Make sure there is a bodygyro.

0

I edited tell me wether it works.

You should split the rotation between the neck motor6d and the waist motor6d

try this: (client script)

local tiltAtEvent = game.ReplicatedStorage:FindFirstChild("tiltAt")
local camera = workspace.CurrentCamera

local function onUpdate(dt)
	tiltAtEvent:FireServer(math.asin(camera.CFrame.LookVector.y));
end

game:GetService("RunService").RenderStepped:Connect(onUpdate)

and then: (server script)

local tiltAtEvent = game.ReplicatedStorage:FindFirstChild("tiltAt")

local neckC0 = CFrame.new(0, 0.8, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1);
local waistC0 = CFrame.new(0, 0.2, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1);

tiltAt.OnServerEvent:Connect(function(player, theta)
	local neck = player.Character.Head.Neck;
	local waist = player.Character.UpperTorso.Waist;
	
	neck.C0 = neckC0 * CFrame.fromEulerAnglesYXZ(theta*0.5, 0, 0);
	waist.C0 = waistC0 * CFrame.fromEulerAnglesYXZ(theta*0.5, 0, 0);
end)

make sure to make a remote event in replicated storage called tiltAt

2 comments

0

You do not need a remote event all you have to do is add a bodhgyro and check the position of the mouse.

0

the thing i dont really like about using bodygyros for moving the player is that it looks like the person is flying. bodygyros are a lot easier to use tho

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