- Home /
Question by
jackblack2215 · Oct 24, 2017 at 03:08 AM ·
rotationtransformif-statements
Rotation Lock
I watched a YouTube tutorial to get this code, it works just fine. My problem her is that I tried to limit the rotation of the x axis movement with the eyes game object. It is the bottom if statement in the code and It doesn't work at all, nothing changes.
using UnityEngine;
using System.Collections;
public class MovementPlayer : MonoBehaviour {
public float speed = 2f;
public float sensitivity = 2f;
CharacterController player;
public GameObject eyes;
float moveFB;
float moveLR;
float rotY;
float rotX;
void Start () {
player = GetComponent<CharacterController>();
Cursor.visible = false;
}
void Update () {
moveFB = Input.GetAxis("Vertical") * speed;
moveLR = Input.GetAxis("Horizontal") * speed;
rotX = Input.GetAxis("Mouse X") * sensitivity;
rotY = Input.GetAxis("Mouse Y") * sensitivity;
Vector3 movement = new Vector3(moveLR, 0, moveFB);
transform.Rotate(0, rotX, 0);
movement = transform.rotation * movement;
player.Move(movement * Time.deltaTime);
if (rotY < 80 || rotY > 300)
{
eyes.transform.Rotate(rotY, 0, 0);
}
}
}
Comment