Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Descending Slopes

Discussion in '2D' started by elgatodorado, Sep 4, 2019.

  1. elgatodorado

    elgatodorado

    Joined:
    Apr 7, 2019
    Posts:
    22
    Hello, I am making a platformer 2D and I am having a problem with my slopes.

    I solucionated a problem I had when ascending the slopes with a material adding more friction, but when the character descends it makes a little jump (because of the physics) and what I would want that the character will walk over the slope.

    I am very new in Unity and all the solutions I found are with Raycast and I don't undestand them(I never used Raycast).

    If someone can explain me how to do this or knows good tutorials it would help a lot.

    Thank you for your time.
     
  2. bloodwolftico

    bloodwolftico

    Joined:
    Nov 13, 2017
    Posts:
    100
    Playing around w materials usually fix problems w slopes, yes. It depends on what you want to do. 0.1 friction can help stop sliding down gentle slopes, and 0 friction can help make sure the player is not getting stuck on platforms when hitting a platform from the side...

    If your character is jumping up when sliding down, sounds to me the collider your ground/surface is using may have little bumps in it. Can you run a test by selecting the ground collider and the character collider, and make sure Scene View (where you edit and move stuff) is visible? (By default, Unity will switch to Game View when you hit play (at least in the version and layout im using)). My goal here is to determine whether the player is hitting invisible collider bumps when he slides down.

    Maybe you can show us a screenshot of how your ground collider looks like?
     
  3. elgatodorado

    elgatodorado

    Joined:
    Apr 7, 2019
    Posts:
    22
  4. bloodwolftico

    bloodwolftico

    Joined:
    Nov 13, 2017
    Posts:
    100
    I see. How do you move your character? GetAxisRaw? Rigidbody.AddForce? transform.Translate?
     
  5. elgatodorado

    elgatodorado

    Joined:
    Apr 7, 2019
    Posts:
    22
    First I take the direction with GetAxisRaw and then I do this:

    Code (CSharp):
    1. transform.position = transform.position + new Vector3(velocity* h * Time.deltaTime, 0, 0);
    h is the variable I use to take the direction from GetAxisRaw.

    Thank you for your time.
     
  6. bloodwolftico

    bloodwolftico

    Joined:
    Nov 13, 2017
    Posts:
    100
    I am thinking that transform.position is moving your character on the X axis, and it has enough strength to push it beyond the flat Edge collider, so your character is temporarily in the air (really close to the ground but not touching it) then falls down due to gravity, and it all happens kinda fast so it looks like you are hitting little bumps while moving.

    Have you tried reducing the strength of how fast your character moves on the X axis? Or have you tried using a physics-based movement code, like Rigidbody.velocity ? I think it's worth a shot and see if you get different results.
     
  7. elgatodorado

    elgatodorado

    Joined:
    Apr 7, 2019
    Posts:
    22
    Hello, I couldnt answer before.

    -If I reduce the velocity of my character the game would be very slow.

    -I tried using Rigidbody2D.velocity and I get the same results.

    In conclusion I am in the same situation.

    Thank you for your time.
     
  8. bloodwolftico

    bloodwolftico

    Joined:
    Nov 13, 2017
    Posts:
    100
    Have you tried using a different collider? Not edge but a basic form like Box or Polygon.
     
  9. elgatodorado

    elgatodorado

    Joined:
    Apr 7, 2019
    Posts:
    22
    Yes, same results