Swapping model parts

Hello. I am working on my game and i’ve decided it would be a good idea to implement some kind of equipment/items system. What is the most efficient way to do this? I made a model with 3 weapons (2 hidden under ground so they wouldnt get rendered). Is there any “clean” way to swap the weapons in the hand of the model itself so i dont have to make specific animations for each one? Or is it usually done programatically? I am completely new to gamedev and i have no clue how to do that

If it for items in hand, animation isn’t necessary. It is sufficient to attach it to attachment Node of jme skeleton.
This way you can put your items as separate .j3o files and attach them with a function.
Eg. if you are using SkeletonControl then:

rig.getControl(SkeletonControl.class)
.getAttachmentsNode("nameOfHandBone")
.attachChild(item);

Thank you, i’ll give it a try

okay, i tried it and SkeletonControl class is deprecated. is there any workaround that you know about kind sir?

SkeletonControl still functions; it’s deprecated because it’s part of the old (JME 3.2) animation system.

The corresponding class in the new animation system is SkinningControl, and it provides a similar functionality via its getAttachmentsNode() method.

Okay, so i established SkinningControl for playerNode child armature, accessed bone.004, and tried attaching another spatial to it. Doesnt work though. Are there any prerequisites for it to work? Because i couldnt find much information about that. Here are the models and the code:

Can you be more specific?


At least from my basic understanding of what i managed to do up till now, the weapon model should get attached to the attach node of bone.004, but it didnt get attached/ doesnt show up for some reason i dont know about

Your scene is super dark (maybe PBR with no light probe?) but looks like there is a gun there.

what i meant by prerequisites is: does the weapon model itself has to have a bone i need to adress somehow?

No.

yeah the scene is quite dark but there actuallyis some light i made (you can see the textures) and the gun is originally part of the soldier model, and i wanted to attach this model to his left arm for testing purposes

Standard debugging stuff…

Add the weapon to the scene without attaching it to see if it even displays. Or is super small or super big. (We don’t know either)

Then try attaching it to the attachment node thing… and System.out.println() its world position, etc. to see if it’s reasonable.

Yeah, but if it’s exported as GLTF then it will be using the PBR shader… and that will look dark without a light probe because you will never have any ambient light.

Okay, thanks. I will give it a try right now, as i said i am new to gamedev and havent thought about about testing it that way

when i attach the weapon model itself to the rootNode it is perfectly visible, but whenever i attach it to model bone attach node it invisible + its coordinates are always 0,0,0 no matter whether i move the playerNode

Be. More. Specific.

Show. Code.


there is the code responsible for attaching the weapon, moving playerNode, and checking current weapon position

note that the player was continuously moving around so the playerNode coordinates were not 0,0,0

and here’s the result of attaching the weapon to the rootNode

World. Not local. You are printing the local translation which of course won’t change.

I mean, I just looked into my own code and there is nothing special about attachments:

SkinningControl skin = armature.getControl(SkinningControl.class);
skin.getAttachmentsNode("Grip_R").attachChild(sword);

Edit: P.S.: you don’t have to paste screen shots of your code all the time. Makes it a pain to quote.