Attaching dynamically generated entities to bone

Hello …
I’m trying to attach some sphere colliders to the hands of a punching boxing character…
Which they must be programmatically generated because the fbx bones are not accessible in the editor…

  1. I get the desired graph node within the model

var graphNodeLeftHand =

  1. Dynamically generate an entity… and attach the collision component to it
this.entityLeftHandCollider = new pc.Entity(); = 'LefttHand';    
var collisionLeftHand = this.entityLeftHandCollider.addComponent("collision");
collisionLeftHand.type = "sphere";
collisionLeftHand.radius = 0.26;    
  1. Create and attach the model component to the newly created entity
this.entityLeftHandCollider.model = new pc.Model();
  1. Create and attach the graphnode component to the newly created model
this.entityLeftHandCollider.model.graph = new pc.GraphNode(); = 'LeftHand';
  1. None of these two options worked to ‘attach’ the newly created entities to the desirde graphnodes of the owner entity…
//graphNodeLeftHand.addChild( this.entityLeftHandCollider.model.graph );
this.entityLeftHandCollider.model.graph.reparent( graphNodeLeftHand );
  1. When checking on the whereabouts of the objects… They were created… However they dont seem to be properly attached to the bone hierarchy because they don’t move when the character animates, thus the position of the sphere colliders remain at 0,0,0 and the path is “”

Boxer.prototype.update = function(dt)
var v3Pos1 = this.entityLeftHandCollider.getPosition();
var v3Pos2 = this.entityRightHandCollider.getPosition();

console.log( "Tracer "+
              this.entityLeftHandCollider.getPath() +" - " + ") "+
              v3Pos1   +" - "+
              this.entityRightHandCollider.getPath() +" - " + ") "+
              v3Pos2 ); this, dt );


yields: " Tracer - LefttHand) [0, 0, 0] - - RightHand) [0, 0, 0] "

as far as i can see you are reparenting the model and graph of the entityLeftHandCollider but not the entity

try entityLeftHandCollider.reparent('graphNodeLeftHand ')


I must admit I have to reread and reinterpret the code as written… I wasnt aware that components could be bounced around like that and not just entities… Many Thanks for your prompt reply (doing playcanvas in the middle of Global Gamejam where everybody else uses unity or unreal =D )…

1 Like

Im not sure they can be bounced around like that but thats what you were doing. GL with the game jam, show those native engine users what for

1 Like