GMOD-Inspired body-rotation system

So, in my game there is a default rig, the only parts we can use are the HumanoidRootPart and Camera.

So. when the camera suprasses a 45 degree angle (to left or right, from where the humanoidrootpart is) How would i make the body turn and look to where the camera is now?

(Example below, Red is the angle based off the rootpart, Orange is the camera angle)


How would i achieve this?
And how would i even make the angles work off the rootpart?

Still need help on this, anyone can help?

do you want it so when you move it rotates to the right and left?

1 Like

Yeah, basically like that, thanks for the quick response too

uhh probably make a script that tweens the cameras cframe angle when the A or D button is pressed and whenever you look past the angle it tweens back to original angle

Not quite, im saying when your using your camera in first person, and when you pass a certain angle, you tween the rig to face your camera

i dont know if thats possible since it will always be updating the cam position so like if your 180 degrees then it would go off even though the rig is infront of you

Disable Humanoid.AutoRotate

Id use something like :Dot() in angle between the humanoidrootpart and camera to find the difference and if its larger than the threshold, apply an alignorientation to rotate the player.
something like

if math.deg(math.acos((workspace.CurrentCamera.CFrame.LookVector * Vector3.new(1,0,1)):Dot(Character.HumanoidRootPart.CFrame.LookVector * Vector3.new(1,0,1)))) > 70 then
  AlignOrientation.CFrame = CFrame.new(Vector3new(), workspace.CurrentCamera.CFrame.LookVector * Vector3.new(1,0,1))
end

havent tested this, and I’ve left some things out but as a proof-of-concept it should work for you
you could also consider other methods to rotate the player

edit: DO NOT use tween to rotate your character!!! tweens are interrupted by changes such as those caused by physics and are not preformant!! I highly recommend a physics based approach since thatll also sidestep the issue of glitching into walls by directly setting the rotation.

1 Like

Is there a way to make the rig face the camera when walking?

And also ,i cannot tween the align orientation either, is that what you were saying?

nevermind lol i realized i can just use move direction and paste the lower code,

no i would just set the align orientation’s cframe and let physics do the job. if you are doing this you should

  • disable autorotate in the humanoid
  • increase the maxtorque (i think thats what its called) etc
  • dont forget that you need to set a Attachment0
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.