I have a scene with SpongeBob, a basketball, and a player. SpongeBob says “Hi! i’m SpongeBob!” when I touch him as a player, but also plays the noise when the basketball touches him. This gets annoying fast, is there any way I could make it so SpongeBob only plays the noise when the player hits him?
Here’s my code:
var Collider = pc.createScript('collider');
// initialize code called once per entity
Collider.prototype.initialize = function () {
this.entity.collision.on('collisionstart', this.onCollisionStart, this);
};
Collider.prototype.onCollisionStart = function (result) {
if (result.other.rigidbody) {
this.entity.sound.play("hit");
}
};