function Awake() { rigidbody.AddForce(4, 4, 0, ForceMode.Impuls); } but this is for 3D rigidbody. Do u know how can i convert this code into “2D”? (I try this:
function Awake() { rigidbody2D.AddForce(4, 4, ForceMode.Impuls); } but it is error : Assets/Scripts/Ball.js(4,29): BCE0017: The best overload for the method ‘UnityEngine.Rigidbody2D.AddForce(UnityEngine.Vector2)’ is not compatible with the argument list ‘(int, int, System.Object)’.
I would suggest making a more descriptive title if you want more people to read your post. As for your question, the error message is fairly descriptive: you need to make sure that the variables your passing into the function match the type of variables the function is looking for. In this case, instead of putting rigidbody.AddForce(4, 4, 0, ForceMode.Impuls), you have to put rigidbody.AddForce(new Vector2(4, 4), ForceMode.Impuls).
function Awake()
{
rigidbody2D.AddForce(new Vector2(4, 4));
}
This is the best you can do it because there is no force mode for the 2d rigid body.
Should have same results because the force is only applied once, making it instant.