[SOLVED] Entities of fbx

In Unity, my fbx consisted of a lot of entities. As a result I could shoot from the gun that moved with the animation. How do I do something like that with Playcanvas, because I can’t find the exact position of the gun…

Even though the internal hierarchy of a model isn’t exposed in the editor (and would be cool to have this feature at some point), if there are bones included in your model they will get appended to the hierarchy on runtime.

That means you can use regular pc.Entity/pc.GraphNode methods to find and reference them, like findByName(‘boneName’).

Aha oke. I think i can use blender to find the bone name that i need?

Yes exactly, the bone will use the same name when used in Playcanvas.

You can also use console.log or the browsers debugging tools to explore the hierarchy of your entity, that is rendering a model with bones. In the children property you will see entities named like RootNote and after your bones names.


Okay, I think that I can improve many things with this. I’ll try it later. Thanks for your information!

1 Like

It works! I can set a rotation from an invisible entity. However, a few things that are weird.

  • I have to use the z axis to get the good y axis

  • I have to invert, otherwise is going in the wrong direction

        var rotation = new pc.Quat(0, this.entity.findByName("Bip001 Head").getRotation().z, 0);

Also i try to set a little offset in the viewField rotation (for example 10 degrees), but i can’t get this working:

        var rotation = new pc.Quat(0, this.entity.findByName("Bip001 Head").getRotation().z + 10, 0);

I like to use one line to keep my code clean, all in all I would get about this:

 this.viewField.setLocalRotation(new pc.Quat(0, this.entity.findByName("Bip001 Head").getRotation().z + 10, 0));

The points you mention most likely are due to local vs world space translation, so yes you will have to find someway to accommodate for those differences much like you do.