I want to create a script, which controls my camera using my mouse, like a basic MouseLook script. But, I want the camera to move with the head, and when the head reaches a specific angle, I want the whole body to move... I can't figure it out. I have been using Unity for more then a year now, trying to finish this since MONTHS. I think it's about time I learn something more advanced. Any help appreciated, thank you!
Possible solution: (I guess that moving the camera == moving the head in your project)
You can get relative angle between head Transform.eulerAngles
and body Transform.eulerAngles
just using Vector3.Angle
( https://docs.unity3d.com/ScriptReference/Vector3.Angle.html ) Then, in the Update
method you can rotate your body manually, for example, Rigidbody.MoveRotation
( https://docs.unity3d.com/ScriptReference/Rigidbody.MoveRotation.html ).
You can also lerp this rotation to make it smoothly. (I can help you more presizeliy if you add some code)
And 7 months later, I'M BACK!
public GameObject playerHead;
public GameObject character;
void Update()
{
//check if the head is at a specific angle and if the mouse is moving
if (playerHead.transform.localRotation.x >= 0.59f && Input.GetAxis("Mouse X") < 0) {
//rotate the body at the speed of the mouse
transform.Rotate(new Vector3(0, Input.GetAxis("Mouse X"), 0));
//repeat
} else if (playerHead.transform.localRotation.x <= -0.59f && Input.GetAxis("Mouse X") > 0) {
transform.Rotate(new Vector3(0, Input.GetAxis("Mouse X"), 0));
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.