Trigger animation upon proximity

Hi guys, is there a way to activate an animation or animation set added to an Entity, when my avatar has certain proximity to it?

Example… I have a third person avatar,
I move my avatar close to an Entity, that has a model and an animation
the Animation in the Entity starts playing

Thanks. I`m very new to playcanvas, any help ill be gratefull.

Assuming your character is a rigidbody, I think you can easily achieve this with a trigger volume listening for “triggerenter”.

this.object.collision.on("triggerenter", function (entity) {
    entity.animations.play("animationName");
});

This two sheets will help you:

Yeah, of course you can. If you want proximity, then you need to save your avatar’s world space position to a Vec3 variable. And you have your object’s world space position. Then:

var distance_vector = avatar_vector - obj_vector;
var distance = distance_vector.length();
if (distance < my_proximity) {
//play animation here
}

I am not completely sure in my code, but I hope you’ve got the idea. Just use vector algebra for proximity tasks.

Ey guys, thanks for the help, it was just what i needed.
I used this base

this.object.collision.on("triggerenter", function (entity) {
    entity.animations.play("animationName");
});

But instead of entity.animations.play(“animationName”); i used an app.fire controller to trigger actions on different entities. So, very cool.