Search Unity

Sliding movement

Discussion in 'Physics' started by Guigger, May 22, 2021.

  1. Guigger

    Guigger

    Joined:
    Oct 31, 2016
    Posts:
    1
    Hi all,
    I am trying to implement a sliding system in my 3D game but I am having some difficulty. Currently I am using Mathf.Lerp() to interpolate between two different speeds of sliding so that the player appears to slow down over the duration of the slide. While this works, it doesn't give the most desirable effect, I would like to make it so that the slides duration is dependent on the gradient of the surface that they are on. For example, if they are on a hill, the player would continue to slide until the gradient flattens out again. How would I begin going about this? Many thanks in advance.
     
  2. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    674
    I think you want the raycasthit.normal on the ground
    then getting the vector3.angle between the normal and the player.forward or the vector3.up

    more on this: 1 2 3