Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

How to achieve mario like kill mechanics?


MisterMaSK
 Share

Recommended Posts

so i am making a platformer and i'd like to achieve mario like kill mechanics..

like if the player jumps on top of a say demon the demon dies but if the player touches the said demon from either side - right left or bottom, the player dies....

just like in mario if mario touches the moustache creatures mario dies or even if they fall on mario, mario dies

but if he jumps or falls on top of them, they die..... 

Link to comment
Share on other sites

You can use Sprite.body.touching to determine which side of the sprite is currently colliding.

 

Sprite.body.touching is an object with the following properties - left, right, up, down, none - each of which is set to true or false.

 

http://gametest.mobi/phaser/docs/Phaser.Physics.Arcade.Body.html#toc48

 

 

You could probably use a combination of Sprite.body.touching and the position of both sprites to determine what the outcome of the collision should be.

Link to comment
Share on other sites

There is an object in the physics body that tells you what side of the body is touching something else.

Look for 'touching' in the Body class.

I think it is only set on collisions, so you will need to be using the built in physics to use it.

In your update function, the object you pass into the collision detection function first gets passed to the collision handler as the first argument.

I'd recommend putting all the enemies into a single Phaser.Group so you can test collisions between that group and the player.

In the collision handler, you would check which side is touching and react accordingly.

collideEnemy = function(player, enemy) {    if ( enemy.body.touching.up )    {        //Call a jump function or something here...        player.body.velocity.y = -200;        //Maybe put the enemy into a different group so it doesn't collide with the player anymore...        enemy.kill();    }    else     {        //You would probably want something a little more than this...        player.kill();    }}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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