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

Can't get 2d character to glide (when w button is pressed)

Discussion in '2D' started by MyFriend, Dec 3, 2014.

  1. MyFriend

    MyFriend

    Joined:
    Dec 3, 2014
    Posts:
    1
    Hi I'm making a 2d game similar to Rayman Origins, and I want to be able to press and hold the w key to make the character glide does anyone know how to do this?
     
  2. PeterD

    PeterD

    Joined:
    Feb 6, 2013
    Posts:
    120
    Vary the gravity on the character when w is pressed. This will make the character fall slower. I don't think I used anything any more sophisticated than that when I did a similar thing.

    Edit : Don't forget to take velocity into account as your character will not slow if they are already hurtling towards the ground. Only if the gravity is reduced at the top of a fall, when velocity is initially very low anyway.

    Looking at my old code. I apply an impulse to slow the character when the glide key is pressed as well as lowering the gravity for them. So they appear to almost but, not quite halt their fall in mid flight.