[SOLVED] Adding Gun to Player Model

How can you add a gun model to a player model?
Both my models are in fbx format.

There are many similar threads that should be a good starting point:

1 Like

@mvaligursky How can I reference a bone itself? I seem to be referencing it wrong. Not getting any errors but the gun model is not attaching to the bone at all.

Hi @Alexis_Shaju! What does your current setup look like? Do you want to add the gun by script or in the editor?

@Albertos At the moment, I physically set the gun inside of the player, and it looks alright, I don’t know. What I want to achieve is the right index finger wrapping around the trigger, and the gun to be in the right hand, held onto by the left hand as well if possible. How do I achieve this? Which setup is easier?

You can make the gun entity a child of the hand entity and then the gun will move with the hand. But if you want to make it that accurate, I think you should use a program like Blender where you can fine-tune the animation(s) with the model(s). This will not be easy without experience.

How is it possible to do this by code? Like how do you add the gun to the hand by script?

There are different ways to do this.

If the gun entity is already part of the hierarchy, you can use this:

gunEntity.reparent(handEntity);

If the gun entity is not part of the hierarchy yet, you can use this:

handEntity.addChild(gunEntity);

It works :smiley: , except it’s massive, in the sense that like this.

I’m not totally sure what I see on the picture, but you can adjust the scale of the model by script as well.

https://developer.playcanvas.com/en/tutorials/manipulating-entities/#scale

What you also can do is prepare everything in the editor and just enable and disable it by script.

I had this method working before. Just was wondering if attaching by script worked better, but I went again with placing it myself. Doesn’t look the best, but it’s ok