Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Too high forces to move

Discussion in 'Scripting' started by Maklaud, Oct 15, 2017.

  1. Maklaud

    Maklaud

    Joined:
    Apr 2, 2013
    Posts:
    551
    Hi All,

    I'm making some code from the tutorial (character movements and jumps) and here is how it's imlemented:

    Code (CSharp):
    1. fighter.Body.AddRelativeForce(new Vector3(0, VerticalForce, 0));
    2. ...
    3. fighter.Body.AddRelativeForce(new Vector3(HorizontalForce, 0, 0));
    Where Body is Rigidbody2D.
    VerticalForce and HorizontalForce are set in the editor.

    Original tutorial is 3d, but my version is 2d, so I have every physics item in 2d (box collider instead of capsule collider etc). Original values are about 50-180, but I decreased them to 4-8. Anyway, my character jumps and moves with too high forces.

    For example, I press the left arrow, my character moves left too high. When I release the left arrow, it must stop, but is continues to move. Values < 1 don't work at all - character doesnt move or jump.

    How can I fix that and make smooth movement?
    Thanks!
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    You can start by increasing the mass of your rigidbody, and then adding more drag forces to help them stop faster after you release input.

    If you're looking for Megaman style instant-control though, you'll want to just set the velocity directly.
     
  3. Maklaud

    Maklaud

    Joined:
    Apr 2, 2013
    Posts:
    551
    Hi GroZZleR, thanks for the reply!
    Don't know about Megaman. I need just a simple controller - moving, jumping etc. Will try to set mass. Thanks!