How can I make something active on collision? For example, I have a cat in a tree. The cat should be fixed where it is initially until it is hit with a rock, at which point it should fall. I have my code so far below.
var timeHeld = 0;
var prjctle;
var cat;
var cat2;
var score = 0;
var catAmt = 2;
class Game extends Phaser.Scene{
constructor(){
//super() inherits all the characteristics of the Phaser "scene" class
super("game"); //Identify the current class with "playGame"
}
create(){
var gnd = this.physics.add.staticGroup();
gnd.create(0, 376, 'gnd').setOrigin(0,0).setScale(8,8).refreshBody();
cat = this.physics.add.staticImage(300,100,'cat').setOrigin(0,0).setScale(4,4).refreshBody();
cat2 = this.physics.add.staticImage(360,180,'cat').setOrigin(0,0).setScale(4,4).refreshBody();
var basket = this.physics.add.staticImage(310,354,'catBskt').setOrigin(0,0).setScale(6,6).refreshBody();
prjctle = this.physics.add.sprite(32, 256, 'pebble').setScale(8,8);
prjctle.disableBody(false, true); //So we dont let our first projectile fall down before getting launched
this.physics.add.collider(gnd, prjctle);
this.physics.add.collider(basket, prjctle);
this.physics.add.collider(cat, prjctle, hitCat, null, this);
this.physics.add.collider(cat2, prjctle, hitCat, null, this);
this.input.on('pointerup', function () {
prjctle.enableBody(true, 32, 256, true, true);
this.physics.velocityFromRotation(60, timeHeld, prjctle.body.velocity);
},this);
}
update(){
timeHeld = this.input.activePointer.getDuration();
if(timeHeld > 1000){
timeHeld = 1000;
}
else if(timeHeld < 300){
timeHeld = 300;
}
}
}
function hitCat(cat, prjctle){ //Collision check
// ADD CODE TO MAKE CAT FALL HERE
}