Attaching an entity to a compound entity

@will This is an interesting use case where someone wants a trigger on a compound physics object. Besides making it follow the entity every frame and not having the trigger as a child, is there something we can do here?

well, even if you dont need code, i recommend getting the position of the entity you want to attach the other entity to.
i do it like this.

whateverScript.attributes.add("compoundEntity", {type: "entity"});
whateverScript.attributes.add("attachment", {type:"entity"});

whateverScript.prototype.update = function(){
var com = this.compoundEntity.getPosition();

this.attachment.setPosition(com);
};

I hope it helps, because i dont have any other solution and parenting will not work because it is in the same collision

Thanks

your welcome

be sure to parse the script and choose the compound and attachment entities.

@jus.co_ding_me_23 it didn’t work it just killed sent the enemy (the compound entity) to the respawn point and killed me if i stand in front of it or behind(it’s only supposed to kill you if you stand in front)

i have no idea how to work around that, cant you alter the enemy so it is supposed to kill in front or back and you have to jump over it or something

what did you make the attachment entity be?

can i do something like this?

var ey = com.y - 0.833;

yes, but like this

var ey = this.compoundEntity.getPosition().y;
ey - 0.833;

your method still works

maybe it will work, i have done something similar before

ok

does it work and pls show me the project

@jus.co_ding_me_23 it works but it won’t follow the rotation
is there any way I can fix that?

https://playcanvas.com/editor/scene/1064637
you asked to see the project.

well there are stuff like getRotation() and setRotation(). You could use those.

var Kuddy = pc.createScript('kuddy');
Kuddy.attributes.add("compoundEntity", {type: "entity"});
Kuddy.attributes.add("attachment", {type:"entity"});

Kuddy.prototype.update = function() {
var com = this.compoundEntity.getPosition();
var ey = com.y + 0.861;   
var ex = com.x + 4.211;
    var compy = this.compoundEntity.getRotation().y;
    var compx = this.compoundEntity.getRotation().x;
    var compz = this.compoundEntity.getRotation().z;
  
this.attachment.setPosition(ex, ey, com.z);
    this.attachment.setRotation(compx, compy, compz);
    
};
Kuddy.prototype.initialize = function() {

};

That might have a chance of working, and do you know you can make variables inside variables, like.

var vary = "wow";
var varx = 30;
var thisVariable = varx + vary;
var all = alert(thisVariable);
if(//whatever condition you want){
all;
}

i figured it out already thanks for your help though

@jus.co_ding_me_23 maybe you could help here Gamepad help please