Search Unity

Question Player "loses energy"

Discussion in 'Physics' started by plooploo2, Dec 19, 2023.

  1. plooploo2

    plooploo2

    Joined:
    Jun 28, 2023
    Posts:
    2
    I have a 2-player vertical platformer game. The 2 players compete to see who loses (i.e, falls into lava or touches spike) first. Problem is, the players can push each other, and both of them appear to "lose their energy" afterwards, meaning they lose the power to move in a specific direction (usually they can't jump anymore). I suspect the problem is from the rigidbody2d, but not sure.
    May be related to: https://forum.unity.com/threads/how-to-keep-the-same-velocity-after-bumping-into-things.1040899/
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,491
    Impossible to give you a definitive answer from a brief description above. Just a lot of guess as to what might be happening such as PhysicsMaterial2D bounce, physics isn't 100% energy conserving etc.
     
  3. plooploo2

    plooploo2

    Joined:
    Jun 28, 2023
    Posts:
    2
    it could be the physicsMaterial... although I have nothing assigned to it.
    Screenshot 2023-12-19 100502.png

    A better description: Both players have rigidbodies and are controlled by the wasd and arrow keys, respectively. the code controls their movements by setting the rigidbody.velocity.

    This is what's happening:
    Screenshot 2023-12-19 101507.png
    PS I'm a beginner so i apologize if i'm being naive
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,491
    If you're directly setting the velocity of both then the velocity is entirely controlled by you so how can they "loose energy"?

    I see you've now mentioned it cannot jump. Is this another problem?