2
\$\begingroup\$

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.

\$\endgroup\$
6
  • \$\begingroup\$ What is "SAT" in this context? \$\endgroup\$
    – Phrogz
    Commented Aug 26, 2017 at 13:58
  • \$\begingroup\$ @Phrogz Sorry, that's my mistake, I mean Separating Axis Theorem. \$\endgroup\$ Commented Aug 26, 2017 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
    Commented Sep 3, 2017 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
    Commented Sep 3, 2017 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
    Commented Sep 3, 2017 at 19:51

0

You must log in to answer this question.

Browse other questions tagged .