+1
Answered

custom weapon attachment for generics rigs

ryubi 4 months ago in Shooter updated 4 months ago 3

hi!

i've asked if i can attach a weapon outside of the established bone structure in gc such as head, right hand etc before and you said no.

now can i revise my question to:

how would i go about adding a weapon to any place in a generic player.

scripting is fine too. can i get a general idea about how to go about scripting and which part of GC i have to modify?

thx!

Unity version:
2019.3
Game Creator version:

I do hope this can be answered for you because I'm having a similar problem. I am using a generic spider model and I'm using a sword weapon (with the mesh render turned off) to cause damage. Attaching to Root is very unsatisfactory because the weapon does not move with the spider attack animation as the head lunges but it just moves with the general character rig. Frankly the result looks a bit amateurish specially when I have to try to throw my Player onto the sword to get a response. In other controller systems I have used it has always been possible to attach the weapon manually to *any* bone. It was a bit of a fiddle but it worked. I'm having terrible trouble with the GC method. But it could be just me being useless of course, fully prepared to accept that :). I hope this isn't bad form - coming in on someone else's topic - but the problem is similar.

Answered

If scripting is fine, when you Equip a weapon, an object is instantiated as a child of the bone selected. For example, you can choose to instantiate your weapon at the root of the character. Then, retrieve its reference (it will be the last child of the root object) and set its parent to whatever bone you want.

Bruv, there are multiple approaches when it comes to game dev. Sorry you're not having an optimal experience, but we chose to display a dropdown menu for humanoid characters so simply this process as much as possible. Of course, creating out-of-the-box systems comes at the price of some flexibility, which we try to minimize as much as we can.

+1

figured out a script for this if anybody having the same problem:

  • the WeaponParentReference gets attached to the player and you assign the object that you want the weapon parented to in "Weapon Parent"
  • the AssignWeaponParent gets attached to the weapon prefab
  • the offsets don't work in play mode, so you have to do the transforms on the instantiated weapon and then translate that to the offsets out of play mode
  • since the script is on the weapon prefab, if you have multiple weapons like me, you should have a separate prefab for each weapon!

WeaponParentReference.cs
AssignWeaponParent.cs