Assets\Scripts\PlayerMovement.cs(44,82): error CS1002: ; expected

Please I’m just starting out on Unity and am getting this error message - Assets\Scripts\PlayerMovement.cs(44,82): error CS1002: ; expected, I need help sorting it out…

This is my Code… Thanks

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

public class PlayerMovement : MonoBehaviour
{

    // This is a reference to the Rigidbody component called "rb"
    public Rigidbody rb;

    public float forwardForce = 2000f;
    public float sidewaysForce = 500f;
    private Vector2 lastMousePos;

    // We marked this as "Fixed"Update because we
    // are using it to mess with physics.
    void FixedUpdate()
    {
        // Add a forward force
        rb.AddForce(0, 0, forwardForce * Time.deltaTime);

        if (Input.GetKey("d"))
        {
            rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
        }

        if (Input.GetKey("a"))
        {
            rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
        }

        Vector2 deltaPos = Vector2.zero;

        if (Input.GetMouseButton(0))
        {
            Vector2 currentMousePos = Input.mousePosition;

            if (lastMousePos == Vector2.zero)
                lastMousePos = currentMousePos;

            deltaPos = currentMousePos = lastMousePos;
            lastMousePos = currentMousePos;

            Vector3 force = new Vector3(deltaPos.x, 0, deltaPos.y) + forwardForce
            rb.AddForce(force);   
        }
        else
        {
            lastMousePos = Vector2.zero;
        }
    }
}

It’s exactly as the error says… you’re missing a semicolon ; at the end of line 44. Note that the line number of the problem is in your error message.

Thanks, it cleared that error but changed to this…
— Assets\Scripts\PlayerMovement.cs(44,29): error CS0019: Operator ‘+’ cannot be applied to operands of type ‘Vector3’ and ‘float’

Indeed, you cannot add a Vector3 and a float as you are trying to do. Maybe you meant to scale the Vector3 by forwardForce? Replace + with *. That will clear your compile error but I have no idea if it’s what you want your code to do.

1 Like

Thanks it worked, I am trying to make a game like “Color Bumb 3d”, but I’ve been having issues with the code