- Home /
Movement script (ironically) is not moving.
I wrote this movement script, and one minute it moved, the next it stopped. What did I do wrong and how would I fix it? using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Player_Movement_Script : MonoBehaviour {
float moveFB;
float moveLR;
public float speed = 2f;
CharacterController player;
float rotX;
float rotY;
public float sensitivity = 5f;
public GameObject eyes;
void Start () {
player = GetComponent<CharacterController> ();
}
void Update () {
moveFB = Input.GetAxis ("Vertical") * speed;
moveLR = Input.GetAxis ("Horizontal") * speed;
rotX = Input.GetAxis ("MouseX") * sensitivity;
rotY = Input.GetAxis ("MouseY") * sensitivity;
Vector3 movement = new Vector3 (moveLR, 0, moveFB);
transform.Rotate (0, rotX, 0);
eyes.transform.Rotate (rotY, 0, 0);
movement = transform.rotation * movement;
player.Move (movement * Time.deltaTime);
}
}
So this is weird. Nothing wrong with the script. I wonder what is happening.
Answer by AlienNova · Oct 24, 2017 at 02:02 AM
movement = transform.rotation * movement;
Unity stores rotation as a Quaternion, not a Vector3. I would love to help you further, but I need to see your Move ()
function to help further
Uhm that line is correct. It rotates the movement vector from local space to worldspace. The "$$anonymous$$ove" method is part of the CharacterController.
Answer by Bunny83 · Oct 24, 2017 at 02:39 AM
I don't see anything wrong in your code. Make sure:
You actually attached the script to your player.
Your player object has a CharacterController component attached next to your script.
You did not set speed in the inspector to "0".
Your object is not deactivated or the script is disabled.
You don't set Time.timeScale to 0 somewhere.