Assets/Game/Script/Character.cs(8,24): error CS1003: Syntax error, ',' expected

Hi guys! I am new to Unity, studying how to develop my Pet project. I have wrote this code according to the tutorial but received an error

Assets/Game/Script/Character.cs(8,24): error CS1003: Syntax error, ‘,’ expected

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

public class Character : MonoBehaviour
{
private CharacterController _cc;
public float MoveSpeed - 5f;
private Vector3 _movementVelocity;
private PlayerInput _playerInput;

private void Awake() {
    _cc - GetComponent<CharacterController>();
    _playerInput - GetComponent<PlayerInput>();
}

private void CalculatePlayerMovement(){
    _movementVelocity.Set(_playerInput.HorizontalInput,0f,_playerInput.VerticalInput);
    _movementVelocity.Normalize();
    _movementVelocity - Quaternion.Euler(0,-45f,0) * _movementVelocity;
    _movementVelocity *- MoveSpeed * Time.deltaTime;
}

    private void FixedUpdate(){
        CalculatePlayerMovement();
        _cc.Move(_movementVelocity);
    }
}

I understand that i have to look at line 8 column 24 - but i don’t understand how to fix the issue.
Please help me

Well, here is the code:
public float MoveSpeed - 5f;
Now explain to me please, what did you want to do here and then explain to me what this line of code actually do and then spot the difference.

public float MoveSpeed = -5f;

you missed ‘=’ symbol.

In this code, i am defining how fast the player should move, so i am creating a public float MoveSpeed with the default value 5f.
I am setting MoveSpeed public, because would like to change it from the inspector in Unity.

So you mean that i have change ‘-’ on the ‘=’ ?

If i just change - public float MoveSpeed = 5f;

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

public class Character : MonoBehaviour
{
private CharacterController _cc;
public float MoveSpeed = 5f;
private Vector3 _movementVelocity;
private PlayerInput _playerInput;


private void Awake() {
    _cc - GetComponent<CharacterController>();
    _playerInput - GetComponent<PlayerInput>();
}

private void CalculatePlayerMovement(){
    _movementVelocity.Set(_playerInput.HorizontalInput,0f,_playerInput.VerticalInput);
    _movementVelocity.Normalize();
    _movementVelocity - Quaternion.Euler(0,-45f,0) * _movementVelocity;
    _movementVelocity *- MoveSpeed * Time.deltaTime;
}

    private void FixedUpdate(){
        CalculatePlayerMovement();
        _cc.Move(_movementVelocity);
    }
}

I receive many other issues.

I am moving on the video tutorial from Udemy and can’t get what i am doing wrong because my code looks exatly the same as in the video tutorial.

I have fixed all issues in this code and wrote comments. Code works - character moves on the location.

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

public class Character : MonoBehaviour
{
    private CharacterController _cc; // Reference to the CharacterController component.
    public float MoveSpeed = 5f; // Movement speed for the character.
    private Vector3 _movementVelocity; // The velocity of the character's movement.
    private PlayerInput _playerInput; // Reference to the PlayerInput component.

    private void Awake() {
        // Get references to components when the script starts.
        _cc = GetComponent<CharacterController>();
        _playerInput = GetComponent<PlayerInput>();
    }

    private void CalculatePlayerMovement() {
        // Get input data from the player.
        _movementVelocity.Set(_playerInput.HorizontalInput, 0f, _playerInput.VerticalInput);
        _movementVelocity.Normalize();

        // Rotate the player's movement by 45 degrees.
        _movementVelocity = Quaternion.Euler(0, -45f, 0) * _movementVelocity;

        // Multiply the vector by speed and time to calculate movement in FixedUpdate.
        _movementVelocity *= MoveSpeed * Time.deltaTime;
    }

    private void FixedUpdate(){
        // Call the function to calculate movement and move the character.
        CalculatePlayerMovement();
        _cc.Move(_movementVelocity);
    }
}

Thank you for the help. Have a nice day!

I guarantee you it is not true. You just fixed your first issue, now go through your error messages and fix the rest. I doubt that on Udemy they would mix up = with -. In fact, I challenge you to stop the tutorial, go back and compare your lines one by one and fix all the issues you mistakenly typed wrong. You only can be a programmer if you can type precisely. minus doesn’t mean equal and vice versa. And it will be a bit harder when you don’t just have to copy code like a robot but you need to come up with the code to achieve whatever is it you want to do. So practice and don’t give up.

1 Like

Thank you very much. Totally agree. I will practice!