Error CS1003: Syntax Error, ‘,’ expected

Been getting this code for some reason. Very new to unity obviously lol. Any help would be appreciated:

using UnityEngine;

public class Movement2 : MonoBehaviour;
{
    [Header("Movement")]
    public float moveSpeed;

    public Transform orientation;

    float horizontalInput;
    float verticalInput;

    Vector3 moveDirection;

    CharacterController conn;

    private void Start()
    {
        conn = GetComponent<CharacterController>();
        conn.freezeRotation = true;
    }

    private void Update()
    {
        PlayerInput();
    }

    private void FixedUpdate()
    {
        MovePlayer();
    }

    private void PlayerInput()
    {
        horizontalInput = Input.GetAxisRaw("Horizontal");
        verticalInput = Input.GetAxisRaw("Vertical");
    }

    private void MovePlayer()
    {
        //calculate movement direction
        moveDirection = orientation.forward * verticalInput + orientation.right * horizontalInput;
        conn.Addforce(moveDirection.normalized * moveSpeed * 10f, ForceMode.Force);
    }
}

It seems that you must be following an example from somewhere. You have to compare what is shown with what you have. If you comment all the code in the class body you would/should still get the error which shows you that it must be in this line. Remove the semicolon.

BTW the editor isn’t suggesting that you need a comma it is inferring that you wanted one along with an Interface definition. It doesn’t understand what you have typed but can’t guess what you meant.

1 Like

Do you want to write yet another character controller or do you just want one to play with?

If you wanna make one yourself from a tutorial, keep these two steps in mind:

Two steps to tutorials and / or example code:

  1. do them perfectly, to the letter (zero typos, including punctuation and capitalization)
  2. stop and understand each step to understand what is going on.

If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.

You write in the code above:

But the last time I checked, there is no .Addforce() method on a CharacterController, so definitely don’t go making stuff up here.

If you just want a CC to play with, here’s a handy one I use all the time:

It supports run, walk, jump, slide, crouch… it’s crazy-nutty!!

1 Like