playMaker

Author Topic: Walking on Slopes  (Read 2369 times)

misterjuly

  • Sr. Member
  • ****
  • Posts: 334
Walking on Slopes
« on: January 14, 2021, 10:08:10 PM »
Hello,

I have some slopes in my game and I am using a tile map collider 2d (my game is in 2d). But for some reason, my character won't walk up most of the slopes (especially the steeper ones). Wasn't sure if this is a playmaker or unity thing, but I wasn't sure where else to post this. Thanks!

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Walking on Slopes
« Reply #1 on: January 14, 2021, 10:36:17 PM »
It’s a Unity, or generally, a physics thing.

The proper solution, where the speed is maintained on slopes is advanced even in script, and having moved on from Playmaker, I do not know if actions exist to make it. You would shoot a ray down onto the slope, get the normal, use the vector perpendicular function to get the perpendicular angle (i.e. the angle to move) and set velocity in that direction.

However, the “proper” solution is often not needed or even wanted. If you just want to climb slopes at some lower speed, you detect the slope and get the normal, run through vector angle to get the angle, and if it exceeds some value, tweak gravityscale, drag and your velocity/force while on the slope.

misterjuly

  • Sr. Member
  • ****
  • Posts: 334
Re: Walking on Slopes
« Reply #2 on: January 14, 2021, 11:14:32 PM »
Thanks for the quick response. I think I figured it out. I just changed the type of colliders from tile map colliders to several edge colliders. I know it is a lot more tedious and I'm not sure if eventually performance will take a hit, but it works for now.

misterjuly

  • Sr. Member
  • ****
  • Posts: 334
Re: Walking on Slopes
« Reply #3 on: January 14, 2021, 11:42:49 PM »
A quick follow up question, if I may add, how do I not get gravity to affect the slope? Like, when my character is on a slope, I just want him to stand there, not slide down. Is there something with the colliders that needs fixed with this? Thanks!

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Walking on Slopes
« Reply #4 on: January 15, 2021, 08:45:34 AM »
You can try one or several of these:
— change the physics material on the character, set friction to 1
— reduce gravity scale


misterjuly

  • Sr. Member
  • ****
  • Posts: 334
Re: Walking on Slopes
« Reply #5 on: January 15, 2021, 10:51:52 AM »
Unfortunately, when I adjust those 2 settings, it impacts the way he jumps. I would like to be able to not slide on slopes while not affecting his movement and jumping abilities. Any other suggestions? Thanks!

misterjuly

  • Sr. Member
  • ****
  • Posts: 334
Re: Walking on Slopes
« Reply #6 on: January 15, 2021, 11:32:01 AM »
Also, once I get that figured out, I have one other question. When my player walks on a slope, he does not account for the slope; he is still facing upright. How do I get him to walk at an angle with the slope? Hope that makes sense. Thanks again!

misterjuly

  • Sr. Member
  • ****
  • Posts: 334
Re: Walking on Slopes
« Reply #7 on: January 17, 2021, 01:49:52 PM »
Bump

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Walking on Slopes
« Reply #8 on: January 18, 2021, 08:09:19 AM »
Unfortunately, when I adjust those 2 settings, it impacts the way he jumps. I would like to be able to not slide on slopes while not affecting his movement and jumping abilities. Any other suggestions? Thanks!

That's why you have a state machine. :D In the jump state, you apply one type of setting and when on the ground, another type of setting, and when on a slope a third way and so on.

Also, once I get that figured out, I have one other question. When my player walks on a slope, he does not account for the slope; he is still facing upright. How do I get him to walk at an angle with the slope? Hope that makes sense. Thanks again!

Fairly complicated to do. A few pointers: disable the freeze constraints in the rigidbody, then make a mechanic to align the character in specific states. You have to shoot a ray down, determine the angle, then rotate the vector up towards the normal direction from the ray. Maybe there is a tank turret example somewhere that shows how to rotate towards.

If this isn't essential, and you are beginner, I'd recommend to do tackle other things first and worry about slopes much later. You can also "hide" the problem by making the ground tilted forward or the view angle seem a bit from above, rather than straight on.