Search Unity

Apply Force2D is instant and requires it in the 1000s to be seen.

Discussion in '2D' started by GIRsMySpritAnimal, Mar 23, 2018.

  1. GIRsMySpritAnimal

    GIRsMySpritAnimal

    Joined:
    Jan 13, 2017
    Posts:
    45
    Hi I'm working on a 2D game in Unity 2017.2.0f3 and when I need to apply force to a rigid body 2D it seems I am unable to do it without having it be 1000+ force and applied instantly causing a jerking motion. I even set my rigid body mass to as low as it goes but no change.

    What I need it to do it apply a smooth movement backward instant of instantly teleporting my player and for the value to be less severe to work. Is my only option to add velocity to the player for a few seconds that is higher than their movement speed/velocity? I tried it and it's far from the desired effect.
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    When you use Rigidbody2D.AddForce, the default is ForceMode2D.Force which is scaled by the current fixed-update time i.e. you'll only get a fraction of that force applied. This is used when you're doing this continuously so that you get the force applied in a time-independent way.

    If you want to apply the full force instantly then you should use ForceMode2D.Impulse. Note that if you want to apply an impulse force independent of its mass then simply read the Rigidbody2D.velocity and directly add to that the velocity change you require.
     
    DatDzua likes this.