lukaMis Posted June 17, 2014 Share Posted June 17, 2014 Is there any build in method to get speed of one or other object at collision? I use this: game.physics.arcade.collide(rocket, ground, onCollision);function onCollision () { console.log('collision found. Speed is: ', Math.abs(rocket.body.velocity.y)); }But it logs 0 as rocket is stopped. Ground has properties:game.physics.enable(ground, Phaser.Physics.ARCADE);ground.body.immovable = true;ground.body.allowGravity = false;And rocket gets its speed from this:game.physics.arcade.gravity.y = 75;Do i track manually or is there any helper 'hidden method'? tnxLuka Link to comment Share on other sites More sharing options...
lewster32 Posted June 17, 2014 Share Posted June 17, 2014 Collide also has a processCallback which comes after your collision callback. This is called before the collision (and thus should hold the velocity pre-collision too) and must return 'true' to allow the collision to go ahead, so try something like this (untested):game.physics.arcade.collide(rocket, ground, onCollision, beforeCollision);function onCollision () { // ... collision stuff here ...}function beforeCollision(rocket) { console.log('collision found. Speed is: ', Math.abs(rocket.body.velocity.y)); return true;} lukaMis 1 Link to comment Share on other sites More sharing options...
lukaMis Posted June 17, 2014 Author Share Posted June 17, 2014 @lewster32 Tnx man.Works like charm. I do not even have to pass rocket in beforeCollision since i have it as global game var.Now i do not have to track speed manually in update() anymore.I hope i will have something to brag in the games with Phaser soon. lewster32 1 Link to comment Share on other sites More sharing options...
Recommended Posts