No overload for method 'AddForce' takes 3 arguments. Help

im very new to unity so im having trouble with this error.
the line is 29,61 heres the code:

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

public class NewBehaviourScript : MonoBehaviour
{
      
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey("left"))
        {
            gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(-1000 * Time.deltaTime, 0));
        }

        if (Input.GetKey("right"))
        {
            gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(1000 * Time.deltaTime, 0));
        }
        if (Input.GetKeyDown("up"))
        {
            gameObject.GetComponent<Rigidbody2D>().AddForce(Vector3, 0, 10 * Time.deltaTime, 0, ForceMode2D.Impulse);        
        }
    }
}

1 Answer

1

Hi @serabaflo10,

The problem is here:

            gameObject.GetComponent<Rigidbody2D>().AddForce(Vector3, 0, 10 * Time.deltaTime, 0, ForceMode2D.Impulse);        

You’re not specifying a new Vector3 but rather just a Vector3. I’d recommend looking at your working functions to see the way to implement the new.

This should fix your error.

            gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector3(0, 10 * Time.deltaTime, 0), ForceMode2D.Impulse);        

Hope that helps!