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…
- I get the desired graph node within the model
var graphNodeLeftHand =
this.entity.model.model.graph.findByName(‘DimplesRig:LeftHand’);
- Dynamically generate an entity… and attach the collision component to it
this.entityLeftHandCollider = new pc.Entity(); this.entityLeftHandCollider.name = 'LefttHand'; var collisionLeftHand = this.entityLeftHandCollider.addComponent("collision"); collisionLeftHand.type = "sphere"; collisionLeftHand.radius = 0.26;
- Create and attach the model component to the newly created entity
this.entityLeftHandCollider.model = new pc.Model();
- Create and attach the graphnode component to the newly created model
this.entityLeftHandCollider.model.graph = new pc.GraphNode(); this.entityLeftHandCollider.model.graph.name = 'LeftHand';
- 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 );
- 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() +" - "+this.entityLeftHandCollider.name + ") "+ v3Pos1 +" - "+ this.entityRightHandCollider.getPath() +" - "+this.entityRightHandCollider.name + ") "+ v3Pos2 ); this.functionUpdate.call( this, dt );
};
yields: " Tracer - LefttHand) [0, 0, 0] - - RightHand) [0, 0, 0] "