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

Question [2D] Jumping while stuck on obstacle

Discussion in 'Physics' started by PedroMarangon, Jan 12, 2023.

  1. PedroMarangon


    Feb 27, 2018
    [EDIT] I finally got it working, I just needed to check if the obstacle was in front and, only if not, move the player forwards (otherwise just jump upwards normally)

    I'm making a 2d mobile game where the player runs automatically to the right and the player can jump over obstacles when pressing the left side of the screen. When I do it and the player isn't running into an obstacle (at the moment, just a black square on the ground), the jump works perfectly (stops for the anticipation part of the animation and then jumping forwards). However, if the player is stuck on an obstacle, the forwards part doesn't work, even when I'm in the air and not hitting anymore the obstacle.

    I'm using the Rigidbody2D for movement and yes, I am setting the horizontal velocity on FixedUpdate (also tried putting on Update and LateUpdate, none of these worked). Using a Debug.Log I've noticed that sometimes after the FixedUpdate the velocity X speed resets to 0, even when setting the speed every single frame. Can someone help me out?
    Last edited: Jan 12, 2023