Search Unity

add force not working for some reason

Discussion in 'Scripting' started by ThatOneCake, May 15, 2020.

  1. ThatOneCake

    ThatOneCake

    Joined:
    Dec 2, 2018
    Posts:
    36
    Code (CSharp):
    1. public class Movement : MonoBehaviour
    2. {
    3.     public Rigidbody2D rig;
    4.  
    5.  
    6.     void Update()
    7.     {
    8.         rig.AddForce(1, 0, 0);
    9.     }
    10. }
    11.  

    so iam trying to just add a force but its giving me an error message sayin

    Assets\Movement.cs(17,13): error CS1501: No overload for method 'AddForce' takes 3 arguments

    iduno why please help
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Two things:
    1. The error you're getting is very descriptive. Look at the docs for RigidBody2d.AddForce: https://docs.unity3d.com/ScriptReference/Rigidbody2D.AddForce.html. It does not take three arguments like you have. Try using a single Vector2 argument.
    2. You shouldn't do physics engine stuff in Update(). This should be done in FixedUpdate(). Otherwise your game will behave differently depending on your framerate.
     
    Joe-Censored likes this.
  3. ThatOneCake

    ThatOneCake

    Joined:
    Dec 2, 2018
    Posts:
    36
    thanks dude