Search Unity

I need help finding the best method of approaching this:

Discussion in 'Scripting' started by TheNoobieWaffle, Nov 8, 2014.

  1. TheNoobieWaffle

    TheNoobieWaffle

    Joined:
    Jul 12, 2014
    Posts:
    28
    Hi, I am about to start working on a player mechanics (walking, running, jumping, player gravity) script with C#, and I would like to know the best method to approach a certain problem I see ahead of time.

    When I imagine my player walks off a small ledge (such as a curb), I see gravity take a second to lower my character to the new height. But with such a small height, that means the player is ungrounded for a second and that is not what I want to happen. Rather, I want to raycast and make sure the height is .15 units or smaller, and if so have it basically "snap" to the ground below so the player is never ungrounded.

    My question is how to do this efficiently. I actually want this "check" for .15 unit height to happen every single frame so the player doesn't become airborne from walking down a hill. I know I cannot raycast because that only gets the center of the bottom of the player, so is there a function/anything that allows me to warp a collider to the farthest it can go without going inside another collider or anything?

    Thanks for the help!
     
  2. TheNoobieWaffle

    TheNoobieWaffle

    Joined:
    Jul 12, 2014
    Posts:
    28
    Rigidbody.SweepTest is what I needed. I overlooked it so many times trying to solve this problem.