Search Unity

  1. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  2. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  3. If you couldn't join the live stream, take a peek at what you missed.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  5. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  6. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    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:
    2
    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:
    23
    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:
    2
    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 :/