Sign in to follow this  
evilwizard

Detect platform that sprite is on

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.