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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Need help getting my player to stick to the terrain

Discussion in 'Scripting' started by TheForsaken95, Apr 22, 2015.

  1. TheForsaken95

    TheForsaken95

    Joined:
    Aug 29, 2014
    Posts:
    30
    I can't figure out how to get my character to stick to the ground. He has a kinematic rigid body that does not adhere to gravity, and I would just like him to stick to the ground (Standing upright). I'm not worried about physics, the game I'm making is more of an RTS game, and all that matters is that the person is always right on top of the ground.

    I've tried raycasting, and teleport-sticking him to the terrain, but that only works if he is moving downhill, I need him to stick to the ground when he is uphill too.

    Any help or advice would be appreciated :)
     
  2. ADNCG

    ADNCG

    Joined:
    Jun 9, 2014
    Posts:
    990
    Try raycasting from a few units above your character instead of directly from its transform, so that you're not raycasting through the hill when going up and missing the ground. See if that works!
     
    TheForsaken95 likes this.
  3. TheForsaken95

    TheForsaken95

    Joined:
    Aug 29, 2014
    Posts:
    30
    Man you're a genius, thanks! It worked perfectly.