- Home /
Why doesn't rigidbody2D.AddForce(-5, 2); work?
Assets/Scripts/2DRigid/RigidSwordEnemy.js(54,37): BCE0017: The best overload for the method 'UnityEngine.Rigidbody2D.AddForce(UnityEngine.Vector2)' is not compatible with the argument list '(int, int)'.
Answer by VildNinja · Jan 29, 2014 at 08:06 PM
because it only suppports vectors: https://docs.unity3d.com/Documentation/ScriptReference/Rigidbody2D.AddForce.html
rigidbody2D.AddForce(Vector2(-5, 2));
This is from the scripting reference for a regular rigidbody requiring Vector3 coordinates.
function FixedUpdate ()
{
rigidbody.AddForce (0, 10, 0);
}
I guess putting rigidbody2D before addforce doesn't let it know that you are working with Vector2.
No rigidbody.AddForce(0, 10, 0); is a convenience method if you for some reason not use Vector3 in your code. They apparently decided not to add this for 2D.
Your answer