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. Dismiss Notice

Question Endless runner - How to get jump air time to stay consistent as speed increases

Discussion in 'Scripting' started by ArianB, Jun 7, 2020.

  1. ArianB

    ArianB

    Joined:
    Mar 12, 2018
    Posts:
    8
    So i'm working on an endless runner very similar to subway surfers, and i'm having an issue in understanding how I can make the jump stay consistent as the speed increases. So for an example, if their are coin arcs to collect when jumping, the players jump will stay consistent to that arch no matter how fast the player is going

    Thanks in advance!

    More detailed explanation:
    As the speed increases, the player will seem to linger in the air longer. The obvious method is to just increase gravity, but if i do that i would also have to change the jump force to get the same height, and it can become a little messy to slowly increase these values as the speed increases, while keeping the jump height exactly the same.
    Is there a way to have a specific distance and height for the jump, and then calculate how much air time the player will have based on the speed. That way the player will have the exact same arc no matter how fast he is moving.

     
    Last edited: Jun 7, 2020
  2. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    not sure what you are trying to achieve?

    Do you want your jump shorter if you are moving faster? If yes you can apply more gravity the faster you are moving.

    Anyway I dont know subway surfers but I watched some videos on youtube and the coins are magnetic, you dont have to lineup jumps perfectly to collect them in that game
     
  3. ArianB

    ArianB

    Joined:
    Mar 12, 2018
    Posts:
    8
    Yes, i want the jump to land quicker the faster the player is running. I know i can increase gravity, but I was wondering if there was some way to check where the player is supposed to land based on the speed. And then create a jump arc that will always have the same height, but the air time changes based on speed. Because if i change gravity, then i also have to change jump force, and then it becomes a little messy.
     
  4. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    you need to increase the jump force anyway because your character needs to rise faster aswell to allign with the first half of the coin arc
     
  5. Cannist

    Cannist

    Joined:
    Mar 31, 2020
    Posts:
    64
    If you don't have too many other time-dependent things you might be able to get away with just increasing the game speed instead of the running speed.

    Also, I just remembered this GDC talk, which might be interesting for you:
     
  6. peterdeghaim

    peterdeghaim

    Joined:
    Apr 10, 2014
    Posts:
    154
    Anyone have any luck finding a solution to this? I'm running into the same problem. I can't use TimeScale as other objects in the scene will break if TimeScale increases. But, I need the duration of my jump to remain consistent as the level speeds up. Meaning, the jump doesn't cause the player to traverse further distances than previously

    Currently using a simple Rigidbody Addforce for the jump, played around with using custom gravity scales (given that 3D rigidbody doesn't have gravity scale). No luck finding a perfect algorithm to match anything up

    Any help would be appreciated :)
     
  7. peterdeghaim

    peterdeghaim

    Joined:
    Apr 10, 2014
    Posts:
    154
    Update: Took @Cannist 's advice and just increased the time scale of my game, while slowing down anything that needed to be slowed down - where needed