MisterMaSK Posted December 27, 2013 Share Posted December 27, 2013 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 diesbut if he jumps or falls on top of them, they die..... Link to comment Share on other sites More sharing options...
tackle Posted December 27, 2013 Share Posted December 27, 2013 Do you have a way of determining which side an enemy is of your player? Maybe there's something in the examples? Link to comment Share on other sites More sharing options...
cshepp Posted December 27, 2013 Share Posted December 27, 2013 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 More sharing options...
XekeDeath Posted December 27, 2013 Share Posted December 27, 2013 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(); }} dr.au 1 Link to comment Share on other sites More sharing options...
MisterMaSK Posted December 28, 2013 Author Share Posted December 28, 2013 thanks for the help....ill see if it works... Link to comment Share on other sites More sharing options...
Recommended Posts