Rotating player's character based on part's rotation

The title explains it all.

Example: I have a part with rotation equal to 0, 147.54, 0. I want to rotate player’s character to 0, 147.54, 0 so it is rotated as the part is.

I already tried loads of stuff. One of the stuff I have tried was changing HumanoidRootPart’s rotation but it just breaks movement and doesn’t really rotate the character.

How can I fix my problem?
Ask in replies for more details if needed.

3 Likes

How did you exactly tried to rotate the HumanoidRootPart?

If you’re looking to rotate a character in sync with a part’s rotation, you would do CFrame.Angles(0, math.rad(part.Orientation.Y), 0). Multiply this with the HumanoidRootPart's original CFrame without rotations.

HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.CFrame.Position) * CFrame.Angles(0, part.Orientation.Y, 0)

Edit: Fixed the error.

14 Likes

I used this code:

character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(character:WaitForChild("HumanoidRootPart").CFrame.Position) * CFrame.Angles(0, game:GetService("Workspace"):WaitForChild("Part").Orientation, 0)

and it errored: ‘Unable to cast Vector3 to float’.

What is wrong with that?

1 Like

You forgot about using .Y, you’re trying to set in a Vector3 as an argument within Y.

Thanks! Works well.

Need to add .Y here :slight_smile:

Is this how I’d also rotate my characterRig so that it faces in the same direction the characters gun is facing (faces the mouse pointer, really)…

I’ve tried many things, even things marked as a SOLUTION in the forum, and nothing does it quite right… One solution works fine on the client, not on the server (fail). One solution works on the server, and across all clients, but is TWITCHY(fail). I finally had to scrap it, to come back to it later.

This sounds like it could work, if I made the ‘part’ the guns handle/frame and made the character rotate to match that part.

Whaddya think?

3 Likes