Deleting/Hiding a weapon

Hello everyone,

I have a character with a weapon. It is a spine model.

I’ve been searching everywhere (that I can think of), have no idea of where to find a solution.

I believe that I first need to target the bone/sprite, and then hide or delete it.
In this case I will have an animation where the character loses/drops his weapon (out of screen) and the rest of the animations will simply continue without the weapon.

My guess is that it might cause issues removing a bone, because it is referenced in the spine json animation, so I figured that at least I should be able to hide it (set alpha to 0)

Any help or direction is much appreciated

The game object bones are there so that you can attach other game objects to your spine model. Deleting or hiding them will not have any impact on the spine model itself.

What if the weapon is a separate game object with a sprite or spine model and you attach that to your character model (that now is without a weapon). When the character loses/drops the weapon you simply delete that game object.

1 Like

I like the solution with attaching the gun as a gameobject, the you should be able to have a collision object as well to give the gun physics when it’s detached.

One more possible solution would be to have two Spine skins, one with the gun and one without. You can change skin in runtime with the “skin” property.

3 Likes

Hi and thank you for the response.

So my understanding is that I can’t in my case, target and delete (or set the alpha to zero) a single sprite that is attached to the model.

One issue I feel with the seprate gameobject is how it would follow with the other ones animation (since this character jumps, and moves all the time, even when in idle mode).

But the idea of 2 skins and switch on “weapon lost”-event appeals alot (even thought it will be slightly tedious since I have 30+ characters :D). So I’ll try that one out!

Thanks for the help!

A spine model doesn’t consist of sprites. A spine component is a completely different kind of component from the sprite component.

You should give it a try at least. The separate game object, when attached to a bone in the hand will inherit the transform and thus rotate, scale and in other ways follow along with the bone.

3 Likes

With the separate gameobject approach you should be able to attach the gun to one of the bones, something like:

local gun_go = msg.url("gun")
local hand_go = spine.get_go("player#spinemodel", "right_hand")
msg.post(gun_go, "set_parent", {parent_id = hand_go})

Then the gun will be childed to the right hand bone, and any translation/rotation the bone has will be applied to the gun as well.

4 Likes

Awesome, alright I’ll give that one a try with attaching another game object to it and let you guys know how it went

1 Like

Hello again, so I tried the idea with attaching a game object on another game object like this:

->game obj characters containing 2 figures
-> a separate game object containing single sprite (attachable item, in case a shell, instead of weapon).

in the main collection, I add the first go object, and also the second (shell) go.

So I have it (kind of) working, except I don’t understand the pivot point, because after some fiddeling I manage to have it the correct place, but as soon as some animations go off, the attached item seems to get way off…
(as if the pivot point was somewhere else).

So I guess the question is (assuming it’s just the pivot that’s wrong), where/how do I set that point?

And is the best practice to place it within the original go, or do I adjust the positioning in the collection (where both go are placed together).

All the best,
Alfredo

Attaching some screenshots that perhaps gives a better idea.

I would recommend that you first try to attach a game object with a small circular sprite (not offset) to the spine bone. Is the bone where you expect it to be? If that its the case then next step would be to replace the tmp sprite with the actual sprite you wish to use. You can offset the sprite from the game object to control the pivot point.

1 Like

Hi, thanks for the info.

So I tried to attach a small circle, to the bone called head (just to have a known reference).

I placed the sprite at: x:0, and y:0, on both the gameobject, and in the collection…

somehow it gets offset to the left anyways, I would expect it to be placed near the head bone area.

But yeah I might have to digg deeper, or retry with simple objects (a new spine and single sprite attached)

Attach to multiple bones and compare to how it looks in the spine software. Perhaps there’s a problem with your spine model.