Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

How is this jump possible in unity?

Discussion in 'Physics' started by popeye1, Feb 2, 2015.

  1. popeye1

    popeye1

    Joined:
    Dec 19, 2014
    Posts:
    28
    My jump force is 3000N which is applied as an Impulse.
    My player mass is 100kg
    Gravity is -61.3.

    if ( inputJump){

    rigidbody2D.AddForce (newVector2(0, jumpForce), ForceMode2D.Impulse);
    inputJump = false;
    }

    This makes my player do a good jump but when I calculate on it, it shouldn't be possible.
    But Im thinking that maybe I don't know how long the impulse was applied but I assumed it simulated for 1s.

    For 1s the impulse would be (3000 - 100*61.3 ) x 1s =approx - 3000N which wouldn't allow the player to jump.

    Can someone help me out to explain this? If 1s is not correct please advice how I can get the real time.
     
  2. Uberpete

    Uberpete

    Joined:
    Jan 16, 2014
    Posts:
    78
    We should think about velocity for this:

    So, firstly:
    Imagine a particle with a constant acceleration of g (which, in this case is 61.3 m/s/s).
    Therefore, we have
    So, in Δt, t changes from t1 to t2
    At the same time, v changes from v1 to v2

    Since
    the acceleration downwards is a mere 61.3m/s/s
    3000N of force, on the other hand, gives 300m/s/s acceleration to an object of 100kg, greatly outdoing gravity.

    Hope this helps :cool:
    (if it does, please like - I'm on a like quest :p )
     
  3. popeye1

    popeye1

    Joined:
    Dec 19, 2014
    Posts:
    28
    Yes it helps or simple F > m*g . But I still don't know for how long the force is applied => cant calculate Impulse

    If you how to find this delta time I will give you a like ;)
     
  4. Nubz

    Nubz

    Joined:
    Sep 22, 2012
    Posts:
    553
    You both realize the likes mean nothing here I hope.
     
    Uberpete likes this.
  5. Uberpete

    Uberpete

    Joined:
    Jan 16, 2014
    Posts:
    78
    Its nice to have some anyways (its like saying thanks, a like can make you feel smug - especially when you're a insecure 14 year-old XD )

    This is the physics timestep: http://docs.unity3d.com/Manual/class-TimeManager.html. In game time this is essentially instant (but you can treat it as one second in calculations).

    To get the delta time of each frame, its Time.deltaTime.
     
    Last edited: Feb 5, 2015
  6. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,355
    The force is applied instantaneously (and the docs mention this on the force modes).
     
  7. popeye1

    popeye1

    Joined:
    Dec 19, 2014
    Posts:
    28
    Matthew: yes but this still means is applied for period of time and I was asking for that time.
     
  8. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,355
    0s.

    The velocity is X before the force is added and then instantaneously Y afterwards. It's a physics engine, not reality--you can change the velocity of something without changing its position.

    If you wanted to apply a force over 1s, you would have to apply that force once every FixedUpdate for a second...
     
  9. popeye1

    popeye1

    Joined:
    Dec 19, 2014
    Posts:
    28
    If the force was applied for 0s there wouldn't be an impulse.
     
  10. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,355
    You seem hung up on using real-world physics terminology or something? Time is not a factor in impulses here; you are modifying the object's velocity. The object itself won't move as a direct result of your impulse until the next physics simulation step.

    If you apply a force once, like a jump, its behavior is going to be determined by the rest of your simulation (gravity settings, drag, other forces in play, etc).

    Box2D is open source. Here's the comments around applying an impulse: https://code.google.com/p/box2d/source/browse/trunk/Box2D/Box2D/Dynamics/b2Body.h

    Code (csharp):
    1.  
    2. /// Apply an impulse at a point. This immediately modifies the velocity.
    3. /// It also modifies the angular velocity if the point of application
    4. /// is not at the center of mass. This wakes up the body.
    5. /// @param impulse the world impulse vector, usually in N-seconds or kg-m/s.
    6. /// @param point the world position of the point of application.
    7. /// @param wake also wake up the body
    8. void ApplyLinearImpulse(const b2Vec2& impulse, const b2Vec2& point, bool wake);
    9.  
    And the actual application:

    Code (csharp):
    1.  
    2. m_linearVelocity += m_invMass * impulse;
    3. m_angularVelocity += m_invI * b2Cross(point - m_sweep.c, impulse);
    4.  
     
  11. popeye1

    popeye1

    Joined:
    Dec 19, 2014
    Posts:
    28
    Of course thats one of the reasons I wanted to use unity, a working physics engine .
    Didn't understand if Box2D was a pointer for me to follow regarding impulse or you way of expressing what an impulse is?

    Doesn't matter if you use impulse or force, gravity/drag etc will still influence the body. Can't see why unity would separate it like that, using a well known physics term Impulse and letting it be something else.
     
  12. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,355
    I guess I'm just confused why you're confused? Impulse is used that way across all physics engines, as far as I know. The Box2D link is showing you exactly what's happening under the hood, which should be enough info to calculate jump heights or whatever you're trying to do.

    The thing with physics engines is that time is just an abstraction. Time is essentially frozen when your code is actually running inside of a FixedUpdate callback. It isn't until the next simulation step when velocities and things result in actual movement.

    Your original assumption--that the force was applied over an entire second--was something I wanted to help clear up. Forces are modifying velocities directly, and those will play out depending on the rest of your simulation...
     
  13. popeye1

    popeye1

    Joined:
    Dec 19, 2014
    Posts:
    28
    Maybe Im not clear enough. The Box2d is about how I calculate on things on paper. They use Impulse as well and however you want to explain it still contains a time period which is unknown and asked for in this thread.

    Though you can see Impulse of X as A Newton Force x B times in second. So if I apply 3000 Ns Impulse I was guessing that I could see it as a force of 3000 N applied for 1 second. Why do I need to know this? Because my feeling is that the physics engine isn't reliable and I will also make my game as real as possible (physics based on calculations) . You can see in my other thread for example that gravity isn't really reliable.
     
  14. shaderop

    shaderop

    Joined:
    Nov 24, 2010
    Posts:
    942
    @popeye1: 100% physical accuracy is not a goal of Unity's physics engine or any real time physics engine for that matter. You won't get far expecting accuracy or consistency from such systems. What you will get is real-time performance and good enough realism.

    It's also a good idea to get into the mindset of knowing when to let go and just accept that a certain API call might not mean what you think they do or might not behave like you think they should. Find a workaround that gives you the results you want and then move on. In this case, if you really need to apply an impulse, then you can apply a force over multiple frames and see how that works for you.
     
  15. popeye1

    popeye1

    Joined:
    Dec 19, 2014
    Posts:
    28
    @shaderop: sure Im right now just a beginner of Unity that tries out things. But you're right and Ive had the feeling for several days now that I should let it go but I can't since I know some people now how to work with this engine so you get close to real physics.(working with calculations re forces etc) For example in my thread about gravity, is it supposed to differ up to 2-3x10^-2 (or alternating between two numbers with this difference) when gravity is default? I think its possible to handle this problem but I don't know yet.

    Im okey with to have false values but Im not ok with inconsistent values.