Search Unity

Character Controller Slope Behaviour

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

  1. emilylena

    emilylena

    Joined:
    Jan 18, 2018
    Posts:
    10
    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:
    10
    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 :/