A Trigger volume - triggering a different entity's animation to play once


I am have some problems understanding how to get a trigger to play an animation on a different entity? It just seams not to be clicking in my head. Am I not defining the entity I want to play the animation on?

I know the trigger is firing, but it is says “undefined animation” and my head just is not getting it.
And if it is about the defining the entity, how would I go about defining it?

Iv been stuck on dis almost two weeks now? :sweat_smile:

Here is what I have tried already.

var Inzone = pc.createScript('inzone');

//Inzone.attributes.add('Objects', {type: 'entity', default: 'Door_Cabben01'});
//Inzone.attributes.add('AnimationName', {type: 'string', default: 'Door_Cabben01.json'});

// initialize code called once per entity
Inzone.prototype.initialize = function() {
    this.entity.collision.on('triggerenter', this.onTriggerEnter, "Dylan");

//Inzone.prototype.onTriggerEnter = function(entity) {  
  //  Object.animation.play('AnimationName');     

Inzone.prototype.onTriggerEnter = function (result) {
    console.log("This is it " + result);
    this.Door_Cabben01.animation.play('Door_Cabben01.json',1 );
    //if (result.other.rigidbody) {
    //    this.entity.sound.play("hit");
    Door_Cabben01.animation.play('/ModelsAssets/Door_Cabben01.json',[1] );   

This will be undefined in the code you have posted.


This function call returns a graph node with the name/path that you pass or null if it can’t find it. However you are not storing the return value anywhere.

This is probably what you were aiming for:

    var doorEntity = this.app.root.findByName('/Door_Cabben01');
    doorEntity.animation.play('Door_Cabben01.json',1 );
1 Like

Thanks so much for helping. I have been on holidays since asking, sorry for the late reply. I’ll see if this will work. hopeful it will just get me jump started with getting the rest working.