[SOLVED] Reference specific RigidBody/Entities in scene

I wanted to create a hurt/hit sprite for my character whenever she hits a wall, but it seems she also plays the sprite whenever she collects items. I modified the code found here Collision and Triggers | Learn PlayCanvas and used contact as my event.

Below is the code I used to activate the hurt/hit sprite. I want to make an exception for the “ORBS” category of entities. The orbs have a RigidBody (Static) and Collision component, and have no scripts.

Movement.prototype.onCollisionStart = function (result) {
    if (result.other.rigidbody)) {
        this.entity.sprite.play("HurtSprite");
    }
};

image

I’m at a loss on what to do and help would be most appreciated! Thanks!
project link: PlayCanvas | HTML5 Game Engine

Hi @GAB_VILLAPANDO!

You can add for example a Wall tag to your wall entities and update your code like below.

Movement.prototype.onCollisionStart = function (result) {
    if (result.other.tags.has('Wall')) {
        this.entity.sprite.play("HurtSprite");
    }
};

2 Likes

this is perfect! i was JUST thinking i could utilize the tags, but i had no idea where to start.
thanks so much Albertos!

1 Like