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 Is there a reverse "Step offset" option, So you also snap down large steps

Discussion in 'Scripting' started by lucaskargreen, Sep 10, 2020.

  1. lucaskargreen

    lucaskargreen

    Joined:
    Sep 10, 2020
    Posts:
    21
    The "step offset" in the character controller is perfect for what I want to achieve, is there a way to also reverse the effect using scripts and not messing with gravity while jumping and falling?


    The start of this shows what I'm looking for
     
  2. lucaskargreen

    lucaskargreen

    Joined:
    Sep 10, 2020
    Posts:
    21
    Bumping this, can't figure it out :/
     
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    There's nothing built-in, but you should be able to do it pretty easily with a raycast straight down from your character with a distance of your step height. If you hit the ground within that distance, you can teleport the character to the ground.
     
  4. lucaskargreen

    lucaskargreen

    Joined:
    Sep 10, 2020
    Posts:
    21
    The problem i see with that is that you would also snap when jumping and falling. I thought maybe you could have a timer for "if (!isGrounded for 0,5 sec)" the snapping would stop, but I think it would be impossible to jump then
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,757
    One way is to turn off the snap part when you jump, and turn it back on as soon as you land.

    Also, you probably want to limit how far you cast down otherwise if you come to a huge cliff you'll teleport to the bottom, which is weird.

    I think the video you posted actually does not "snap..." it looks like at least 1 or 2 frames of in-between as he descends, but the camera angle is foreshortened.
     
    PraetorBlue likes this.