Search Unity

Working on Rigidbody Movement?

Discussion in 'Physics' started by kinguhdahood5, Jan 4, 2020.

  1. kinguhdahood5

    kinguhdahood5

    Joined:
    Dec 18, 2018
    Posts:
    84
    So, I wasn't really sure how to phrase what I'm trying to do but I have a rigidbody that works, but I want to configure it. What happens is that when I jump, my horizontal velocity stops once I land, which I don't want. Through script, I've been applying force by adding vector3 forces to velocity. Here's what I have in my script:
    Code (csharp):
    1.  
    2. void checkMovement()
    3.     {
    4.         if (input.left == true)
    5.         {
    6.             if (rigid.velocity.x >= -speed)
    7.                 rigid.velocity += -Vector3.right * accel;
    8.         }
    9.         if (input.right == true)
    10.         {
    11.             if (rigid.velocity.x <= speed)
    12.                 rigid.velocity += Vector3.right * accel;
    13.         }
    14.         Jump();
    15.     }
    16.  
    17. void Jump()
    18.     {
    19.         if (input.up == true)
    20.         {
    21.             if (rigid.velocity.y == 0)
    22.             {
    23.                 allowJump = true;
    24.             }
    25.             else
    26.             {
    27.                 allowJump = false;
    28.             }
    29.             if (allowJump == true)
    30.             {
    31.                 rigid.velocity += Vector3.up * jump;
    32.             }
    33.         }
    34.     }
    35.  
    It's a bit rough, but I've been messing around with components I'm not as familiar with to work on it. I feel like I'm missing something, but I'm not sure why that, after I land, my horizontal velocity jumps to 0. All this is run through the Update function, and this is the only scripting so far that is applying force. I could probably just reset the horizontal velocity on collision enter but this seems problematic going forward with the gameplay I want to achieve.

    Any help would be appreciated, thank you


    EDIT FOUND SOLUTION:

    I found that my collision detection in the rigidbody was at discrete, after I changed it to continuous I achieved my wanted motion, Sorry if you read into this lol
     
    Last edited: Jan 4, 2020