Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    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!