Non-invocable member 'PlayerController.moveDirection' cannot be used like a method.

Hi, I’m extremely new to Unity and any form of coding especially C#. I have encountered a problem whilst following a tutorial on a “FirstPersonController” script. I’ll include the code below but to summarise, I keep getting the error “Non-invocable member ‘PlayerController.moveDirection’ cannot be used like a method”.

How can I resolve this issue as I just want to create a controller so I can continue creating my game?

Thanks for any help in advance!

using UnityEngine;

public class PlayerController : MonoBehaviour
{
    //Public Variables
  
    public float walkspeed;

    //Private Variables
  
    Rigidbody rb;
    Vector3 moveDirection;

    void Awake()
    {
        rb = GetComponent<Rigidbody>();
    }

    void Update()
    {
        //Non-Physics steps
        //Get directional input from the user
     
        float horizontalMovement = Input.GetAxisRaw("Horizontal");
        float verticalMovement = Input.GetAxisRaw("Vertical");

        moveDirection = (horizontalMovement * transform.right + verticalMovement * transform.forward).normalized;
    }

    void FixedUpdate()
    {
        //Physics steps
        //Call the Move function
      
        moveDirection();

    }

    void Move()
    {
        //Here we define the move funtion
        //Rigid.velocity is a method which takes a Vector3 and controls the speed and direction of the GameObject
      
        rb.velocity = moveDirection * walkspeed * Time.deltaTime;
    }




}

UPDATE

The script is almost identical however, I’m recieving even more issues???

using UnityEngine;

public class PlayerController : MonoBehaviour
{
    //Public Variables
   
    public float walkspeed;

    //Private Variables
   
    Rigidbody rb;
    Vector3 moveDirection;

    void Awake()
    {
        rb = GetComponent<Rigidbody>();
    }

    void Update()
    {
        //Non-Physics steps
        //Get directional input from the user
      
        float horizontalMovement = Input.GetAxisRaw("Horizontal");
        float verticalMovement = Input.GetAxisRaw("Vertical");

        moveDirection = (horizontalMovement * transform.right + verticalMovement * transform.forward).normalized;
    }

    void FixedUpdate()
    {
        //Physics steps
        //Call the Move function
       
        Move();

    }

    void Move()
    {
        //Here we define the move funtion
        //Rigid.velocity is a method which takes a Vector3 and controls the speed and direction of the GameObject
       
        rb.velocity = moveDirection * walkspeed * Time.deltaTime;
    }




}

The issues are as follows:

  1. Assets\Scripts\PlayerController.cs(3,14): error CS0101: The namespace ‘’ already contains a definition for ‘PlayerController’

  2. Assets\Scripts\PlayerController.cs(14,10): error CS0111: Type ‘PlayerController’ already defines a member called ‘Awake’ with the same parameter types

  3. Assets\Scripts\PlayerController.cs(19,10): error CS0111: Type ‘PlayerController’ already defines a member called ‘Update’ with the same parameter types

  4. Assets\Scripts\PlayerController.cs(30,10): error CS0111: Type ‘PlayerController’ already defines a member called ‘FixedUpdate’ with the same parameter types

  5. Assets\Scripts\PlayerController.cs(39,10): error CS0111: Type ‘PlayerController’ already defines a member called ‘Move’ with the same parameter types

Can somone explain what these mean as I have no idea how to fix it?

Many Thanks

The issue is exactly what the error says.
You define a variable: Vector3 moveDirection;
then you call it like a method in Fixed Update: moveDirection();
Probably you want to call the Move() method ?

Thanks for the reply, I honestly don’t understand? what part would I need to change?

I suggest you focus on general programming first to get the conecpts of variables, types, methods classes etc… I think its harder to learn programming and game development with Unity in a single batch. Loo kfor the C# yellow book as free but valuable resource. You will have a hard time running to the forum every time you have an error. So you certainly SHOULD learn how stuff works and how you can fix it yourself (hint: the error message is usually quite explanatory).

Also it is considered “impolite” to change your post because people reading the disuccion later get confused. If you have new information to present add it at the end so the flow remains chrono-logical.

Seems your new problems come from a conflict. Probrably there is a PlayerController class somewehre in your project already defined. Maybe you have included the standard assets package? Then you could rename your class or put it in a namespace. But as I said you should learn the basics first.

1 Like

This often happens when you call two scripts the same class name, or copy a file, but leave it in the project folder.
If you’ve done the latter, rename it to something other then .cs