Jump to content

How to get speed at collision


lukaMis
 Share

Recommended Posts

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'? :)

 

tnx

Luka

 

 

Link to comment
Share on other sites

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;}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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