Hello, how can i know the bones name to link a weapon to a bone?
-
Setup your project and click launch
-
In a launched window go to console
-
Enter this:
pc.script.app.root.findByName (âYourEntityNameHereâ).model.model.graph.getChildren();
-
Youâll get an array of child nodes of
GraphNode
type. Expand them to read theirname
fields. Some of them will be skins, but one will be sceleton root - it my case it readsCharacter1_Hips
. -
Expand children of this root further in the console to see your sceleton hierarchy.
Hello, thanks a lotâŚi also have found that if i click on the animation json file and download i can see the file where all the bones are showed, but it isnât easy with every animation file coz of the complexity of the bones.
Where do i do wrong?
lhand = app.root.findByName('Player').findByName('Model').model.findByName('Bip01 I Mano');
Break it down and use the debugger to check whatâs going wrong.
var playerEntity = app.root.findByName("Player");
var modelEntity = playerEntity.findByName("Model");
var graph = modelEntity.model.getGraph();
var node = graph.findByName("Bip01 | Mano");
Hi Dave, just found out, put it too early in the codeâŚbefore the initialize my badâŚnow fighting with attaching the weapon to the bone
hi again,
i used
lhand = this.model.findByName('Bip01 I Mano');
lhand.addChild('shield');
and got:
TypeError: node.getParent is not a function
if(node.getParent() !== null) {
the child âshieldâ must be an entity in the root? or inside player entity? sorry to ask but iâm confused
lhand.addChild('shield')
isnât valid.
The addChild()
method takes an Entity as itâs first argument: http://developer.playcanvas.com/en/api/pc.Entity.html#addChild
Hi again, i tried this code coz i was going nowhere:
and it says TypeError: modelEntity.model.getGraph is not a function
Here is a code, that will get you a list of all available skin bones in model as object, where key - is a name, and value - is a node (bone) that you can manipulate:
var bones = { };
var skins = this.entity.model.model.skinInstances;
for(var s = 0; s < skins.length; s++) {
for(var b = 0; b < skins[s].bones.length; b++) {
bones[skins[s].bones[b].name] = skins[s].bones[b];
}
}
console.log(bones);
Tnx @max i had to change slightly the var skins line coz the script is inside the player entity and not inside the child model, anyway, using alert(bones) i have (object, Object) reply, using console.log(bones) i find nothing am i dumb?
Without piece of code, it is not possible to tell what your problem. Please donât forget providing enough info on issue, including link to source file and link to project.
Possible that your model is not skinned.
https://playcanvas.com/editor/scene/396696
here is the code
`var bones = { };
var skins = this.entity.findByName('Model').model.model.skinInstances;
for(var s = 0; s < skins.length; s++) {
for(var b = 0; b < skins[s].bones.length; b++) {
bones[skins[s].bones[b].name] = skins[s].bones[b];
}
}
console.log(bones);`
is inside Player entity, player script line 62 and follows
Do not use alert
please, that is sooo old school and annoying. Use dev tools and console.
I get this in console, so it finds all it needs:
OK than that means that the bone Bip01 I Mano for the left hand and Bip01 D Mano for the right hand are the right bones to useâŚiâm lost on how to attach the shield object to the left hand coz the shield keep disapearing sigh
So if you parent shield to a bone of that name, it disapears? Make sure your shield origin pivot is at right place, and take in account possible scaling of bones/shield, that will under/over scale it on reparenting.
I have tried to scale the shield like this
` var scale = this.entity.getWorldTransform().getScale();
this.shield.setLocalScale(1/scale.x, 1/scale.y, 1/scale.z);
donât know if i have write it the correct way
and i have tried to put the shield as entity in root and as child in player, i also tried to use it just as model or with collision and rigid body attributesâŚ
Iâm having similar issues as I am replicating this code for use in my own project. @max is there any way that you could explain why the error âmodelEntity.model.getGraphâ is not a function?
Thanks so much for your help!
I have also now viewed this article: How to attach a weapon(Gun) to a character bone?, and put in the code there, but it appears that the gun now is not connected to the character at all! Should the entity be in the scene when we add it?
Hi @TheCodeCrafter i solved that problem not using the object in the scene, but using the same object as child of the character (with no rigidbody if i remember correctly). I set is as child and disable it then when needed i enable it and connect it to the bone. At first it didnât show because it needed to be re-scaled so when initializing the character i rescaled all child objects (shield, sword, etc). You can see the code here studying the player and itâs childs. https://playcanvas.com/editor/project/352037