Search Unity

  1. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  2. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Participate with students all over the world and build projects to teach people. Join now!
    Dismiss Notice
  5. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Character Controller Slope Behaviour

Discussion in 'Scripting' started by emilylena, Jun 7, 2018.

  1. emilylena

    emilylena

    Joined:
    Jan 18, 2018
    Posts:
    3
    Heya guys and gals,

    I need some help with my Character Controller, specifically on slopes. When going down slopes the character noticeably stutters. I'm also unable to jump while on slopes (when using the standard isGrounded functionality. I understand WHAT is happening. I also know HOW to solve it in pseudo code. I just don't know how to go about writing it.

    What is happening is that I move my character on movement vector, which is a straight x / z vector. So if I press forward, my Z increases. If I go up a slope, obviously the game realizes there's something in the way of Z so it pushes the character up. If I go down, there's nothing telling the game that the character should stick to the ground, so it moves forward on the Z, notices it's in-air (so not grounded) and then drops.
    So that's the what.

    How it would need to be solved is that there needs to be a Raycast in the direction of the movement vector to check if there's a slope beneath the character. If there is, apply the movement vector perpendicular to the normal of the surface. That way it "sticks" to the ground if there's a slope beneath the "feet". If not, obviously it will just fall down via gravity as per normal.

    Now I did manage to create that part once, though removed it because it disallowed me from jumping. Which is not what i want since this is first person shooter type movement and both slopes and jumping are equally important.

    If anyone could give me an example in pseudo code or even something you've written yourself, it would be highly appreciated :)
     
  2. DevAigina

    DevAigina

    Joined:
    Jun 6, 2017
    Posts:
    29
    Hi @emilylena
    I don't have any direct answers that can fix your problem.
    But i will give you link to a video that fixes slope problem for 2D maybe it can give you some idea.
     
  3. emilylena

    emilylena

    Joined:
    Jan 18, 2018
    Posts:
    3
    Unfortunately not, but thanks anyways for your comment ^^; I've checked just about every Youtube video about this topic and 9 out of 10 just show to increase your gravity or something similar, and the 1 out of 10 is not applicable to my situation :/