Player turns but won't move forward

Hi there.

I just started with Unity today, and I started by watching all the tutorials. Now I’m following a little starting project guide I found (really basic). But I already have a problem with the SimpleMove function. So far I only have a plane for floor, and a sphere for player. My player will turn when I press the left/right buttons, but he won’t move to the front or the back with the up/down buttons. I had some trouble with the simplemove function, but after looking it up in the reference I think the code is now okay. However, the problem is still there, my player will turn but won’t move.

I even put my code in comment and tried to see if copying the code from the SimpleMove reference page of the website worked, but it still didn’t work. So it doesn’t seem to be a fault in the coding, but I don’t really know where else to look… Maybe I need to import another package to the script, or there’s some other component I need to add in the Inspector or something like that? (I’ve already done the charactercontroller)

using UnityEngine;
using System.Collections;

public class Player_script : MonoBehaviour {
	
	public int speed = 3;
	public int rotatespeed = 3;
	
	void Start () {
		
	}
	
	void Update () {
		CharacterController controller = GetComponent<CharacterController>();
		transform.Rotate(0, Input.GetAxis("Horizontal") * rotatespeed, 0);
		
		Vector3 forward = transform.TransformDirection(Vector3.forward);
		float curspeed = speed * Input.GetAxis("Vertical");
		controller.SimpleMove(forward * curspeed);
	}
}

While typing this, I just wanted to check if I really wasn’t missing something stupid, and I just saw that there’s an error when I press play:

“NullReferenceException: Object reference not set to an instance of an object
Player_script.Update () (at Assets/Player_script.cs:19)”

I tried looking it up, but I didn’t find anything relevant. The “at Assets/Player_script.cs:19” makes me think that the problem is on line 19 ( controller.SimpleMove(forward * curspeed); ), but I really don’t find anything wrong with it?

I hope someone can help me soon!

Thanks in advance!

Corove

GUYS I FIGURED IT OUT IDK HOW BUT DO I DID THIS.

  1. I closed unity completely
  2. Shut off computer
  3. turn back on
  4. log back into unity
  5. open your project
  6. then it should be working again!
    this is what i did and it worked! goodluck:)