Error CS1001: Identifier expected

I am very new to unity and cannot get rid of this error for my fps movemnt script
(16,51): error CS1001: Identifier expected
Any help would be greatly appriciated!!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class moveymove : MonoBehaviour
{

    public float walkSpeed = 6.0F;
    public float jumpSpeed = 8.0F;
    public float runSpeed = 8.0F;
    public float gravity = 20.0F;

    private Vector3 moveDirection = Vector3.zero;
    private CharacterController controller;

    controller  (GetComponent<CharacterController>);
}

void Update()
{
    if (controller.isGrounded);
    {
        moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
        moveDirection = transform.TransformDirection(moveDirection);
        moveDirection *= walkSpeed;
        if (Input.GetButton("Jump"));
            moveDirection.y = jumpSpeed;
    }
    moveDirection.y -= gravity * Time.deltaTime;
    controller.Move(moveDirection * Time.deltaTime);
}

The error message lists line 16, which is this:

controller  (GetComponent<CharacterController>);

But it is incorrect syntax. You already declared a variable named controller a few lines above. GetComponent is written incorrectly, and I don’t think you can GetComponent outside of a method. Lastly I see you are closing the class on line 17, and then have an Update() method floating off into space, but it has to be declared within a class.

That’s all I’ve noticed with a quick look. I’m venturing a guess you wanted it to be something like this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class moveymove : MonoBehaviour
{

    public float walkSpeed = 6.0F;
    public float jumpSpeed = 8.0F;
    public float runSpeed = 8.0F;
    public float gravity = 20.0F;

    private Vector3 moveDirection = Vector3.zero;
    private CharacterController controller;

    void Start()
    {
        controller  = GetComponent<CharacterController>();
    }

    void Update()
    {
        if (controller.isGrounded);
        {
            moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
            moveDirection = transform.TransformDirection(moveDirection);
            moveDirection *= walkSpeed;
            if (Input.GetButton("Jump"));
                moveDirection.y = jumpSpeed;
        }
        moveDirection.y -= gravity * Time.deltaTime;
        controller.Move(moveDirection * Time.deltaTime);
    }


}

Thank you so much! I keep running into the issue of my player just floating into the air, i tried to make a check sphere to reset the velocity on the y axis so it didnt do that but it didnt work, any ideas?

Assuming this script now compiles, the first thing I’d check is the value of “gravity” in the inspector. You have it as 20 in the script, but that’s just a default. It could be a different value in the inspector. You could also play with different values there too. If your character or objects are really big, you may need a much higher value for it to look right.

1 Like