Jump to content

Detect platform that sprite is on


evilwizard
 Share

Recommended Posts

I am creating a platforming game that has multiple different platforms.

Some platforms slope up and others slope down.

Upward Sloping Platforms

* If the character moves right, his y position will increase

* If the character moves left, his y position will decrease

* The angle property of these platforms is negative

Downward Sloping Platforms

If the character moves right, his y position will decrease

* If the character moves left, his y position will increase;

* The angle property of these platforms is positive

The following tries to find the colliding platform.

My update function looks something like this

game.physics.arcade.collide(hero, platforms, function() {
    currentPlatform = platforms.children.filter(p => p.getBounds().contains(hero.x, hero.y))[0];
        gameState.moveRight();
        gameState.moveLeft();
    });
}

I need this platform to calculate whether the character will move upwards or downwards. Here is an example

if (cursors.right.isDown) {
    if (currentPlatform) {
        hero.y = currentPlatform.angle < 0 ? hero.y - 0.04 : hero.y + 0.04;
    }
}

This obviously doesn't work, and the 0.04 value is hard coded, because I can't figure out how to increment with an angle.

I've also tried calling sprite.body.touching, which returns the following

Object {none: true, up: false, down: false, left: false, right: false}

I am completely lost right now.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...