Search Unity

Failing at making a nice rigidbody jump, please help!

Discussion in 'Scripting' started by RoiDanielsen, Sep 27, 2011.

  1. RoiDanielsen

    RoiDanielsen

    Joined:
    Nov 10, 2010
    Posts:
    130
    Hey guys.

    Im trying to make some kind of a 2D game as a learning project. I've tinkered a bit with the movement, and I've figured out the forwards and backwards motion with a rigidbody.

    Now I'm trying to get the rigidbody (just a cube) to make a jump, but as I modified the drag to make the forward/backward motion more smooth, the jump also gets a drag, making the fall down REALLY slow lol.

    I dont really know how to get around this, does any guru have some sympathy with me and want to help hehe?

    Here is my code.

    TL;DR

    How to make the rigidbody fall faster, without reducing the drag so my forwards and backwards motion doesnt get screwed.
     
  2. handsomePATT

    handsomePATT

    Joined:
    Nov 30, 2010
    Posts:
    574
    you could put a constant force on it with a -y
     
  3. RoiDanielsen

    RoiDanielsen

    Joined:
    Nov 10, 2010
    Posts:
    130
    Thanks for the idea. I will try this!
     
    Last edited: Sep 27, 2011
  4. RoiDanielsen

    RoiDanielsen

    Joined:
    Nov 10, 2010
    Posts:
    130
    Well, it works as intended, forces the rigidbody downwards, however, it also impairs the forward/backward movement.

    I can fix this by increasing the forces applied onto the rigidbody, but I dont like the way it works when the rigidbody is in a free fall.

    The extra forces on the back/forth movement makes it extremely fast moving in midair because there is nothing to counterwork the forces, you know.

    I might just make it so that you cant move back/forth while in mid air, but I dont know how to do it?

    Any help?
     
  5. RoiDanielsen

    RoiDanielsen

    Joined:
    Nov 10, 2010
    Posts:
    130
    Okay, I increased the jump height, and tinkered a bit with the mass and drag of the rigidbody, it works like a charm now.

    Still got the flying fast as hell in midair. How can i make it so that if i use w+a or w+d at the same time, it wont move back and forth? Or just something that makes it unable to move while in midair, and only when on the ground?