[Solved] Moving object using AddForce

I’m trying to make a space ship thruster by using AddForce when clicking somewhere in space.
However the ship object refuses to move. I’ll provide with some code and maybe you can help me.

    private Vector3 target;

    public float thrust;
    public float deceleration;
    public Rigidbody2D rb;

    // Use this for initialization
    void Start () {
        //set initial target to current position
        target = transform.position;

        rb = GetComponent<Rigidbody2D>();
        thrust = 1000f;
        deceleration = 1f;
        rb.isKinematic = false;

    }
   
    void FixedUpdate () {

        //Moves the player to the clicked position
        if (Input.GetMouseButton(0))
        {
            //set new target to where player clicked on the screen
            target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            target = new Vector3(target.x, target.y, 0);

            //rb.AddForce(new Vector2(target.x, target.y) * thrust);
            //rb.AddForce(target * thrust);
            rb.AddForce(transform.forward * thrust);
            Debug.Log("ADD FORCE!");
          
        }
}

You’re using a Rigidbody2D. It can’t move forward. Change line 32 of your code to:

rb.AddForce(transform.up * thrust);

Additionally, if you want a vector from A to B, it’s just B - A.

So for a vector from the spaceship to the target, it’d be:

Vector3 force = target - transform.position;

Might also help to compensate for the velocity for smooth movement. I usually do this by subtracting the velocity times some fraction like 0.8 from the force on the object.

Still standing still. Unfortunately.

Note the warning on the Rigidbody2D. Tick the Simulated box again.

Apparently you need a collider…