Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Gravity...without...Gravity?

Discussion in 'Physics' started by DRRosen3, Feb 9, 2015.

  1. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    683
    So I'm attempting to make my character model as realistic as possible when it comes to how it interacts with the terrain. I've achieved making the model tilt in correspondence with the slope of the terrain using this bit of code...

    Code (CSharp):
    1. RaycastHit hit;
    2.             Ray ray = new Ray(my_transform.position, Vector3.down);
    3.             if (terrain.Raycast(ray, out hit, 1000.0f))
    4.             {
    5.                 my_transform.rotation = Quaternion.FromToRotation(my_transform.up, hit.normal) * my_transform.rotation;
    6.             }
    However, this causes the model to slide backwards along the slope. I don't want it to be Kinematic though, but I DO want it to be affected by Gravity. ...but I don't want the model to slide down the slope. Any thoughts?
     
  2. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    683
  3. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    322
    Just a wild guess, but would a physics material with a high friction help?
     
  4. modegames

    modegames

    Joined:
    Dec 1, 2014
    Posts:
    37
    I would use a raycast to determine if the feet are on the ground by having a distance suitable for determining this. If the character in on the ground, then change the velocity on the LateUpdate method to restrict movement by dampening or setting values to zero immediately or when velocity gets under a certain value.