I've been working on implementing slope collision by SAT(Separating Axis Theorem). And then I have a trouble. When my character walks down slope, it moves like a bouncing ball:

enter image description here

The slope has 3 sprites (45°):

enter image description here

Here is my current code with JavaScript:

slopes.forEach((slope) => {
    //Minimum Translation Vector
    let mtv = character.collidesWith(slope);

    if(mtv.overlap !== 0) {
        character.velocityY = 0;
        character.positionY -= mtv.overlap;

It works good when moving up, but bouncing when down, I have no idea how to keep the character stay on slope when walking down. Please, any help would be appreciated.

  • \$\begingroup\$ What is "SAT" in this context? \$\endgroup\$ – Phrogz Aug 26 '17 at 13:58
  • \$\begingroup\$ @Phrogz Sorry, that's my mistake, I mean Separating Axis Theorem. \$\endgroup\$ – undefined000 Aug 26 '17 at 15:00
  • \$\begingroup\$ I solved similar problem by not relying only on gravity to keep the character on the ground but instead when close to the ground the character is instantly "snapped" at the ground level. Faster horizontal speed of course requires bigger snap distance. Another thing is that the first jumping "frame" must be bigger than snap distance. \$\endgroup\$ – Nikaas Sep 3 '17 at 0:49
  • 1
    \$\begingroup\$ @undefined000 My coding skills are not exactly great so I doubt it would be of much use, but still next are the links if you can get something out of them (Unity component on C#) - CharCollisions - parent class with collision-check ray-casts, CharController - child class that moves the character. The main loop is CharController.Update() and CharController.FixedUpdate(). \$\endgroup\$ – Nikaas Sep 3 '17 at 19:48
  • 1
    \$\begingroup\$ @undefined000 Next 2 links were very useful while a was making the character controller The hobbyist coder #1: 2D platformer controller and Platformer controls: how to avoid limpness and rigidity feelings \$\endgroup\$ – Nikaas Sep 3 '17 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.