- Home /
Keeping weapon at the back of character at certain distance
Hello, I currently am using multi-parent constraint to make the weapon in my character's hand to go back of my character. This is working perfectly fine. But when I move, the weapon goes through my character. So what I am trying to do is to keep the weapon at back of character not go through my character. What I want to achieve is much like how the weapon follows the player like in "Genshin Impact". I have tried adding multi-rotation/position constraint but they didn't help at all. I also have tried making an empty gameobject and attaching a script that had a simple follow and lookAt player but still couldn't achieve what I wanted. So I am looking for some other ways I can achieve this. Thanks in advance.
not sure what you want to achieve, maybe you can send a reference video of what you have in $$anonymous$$d ?
Answer by DivainUnity · Sep 13, 2021 at 06:12 PM
Didn't quite get the problem. Does the weapon stays in place? Does the weapon walks with your character? If you're saying that the weapon is "attaching" to the back of your character as expected, I'm guessing the weapon "moves" strangely with your character, which can be caused by your weapon's place pivot gameObject being a child of your character's rig. Put your weapon's place pivot gameObject outside of the rig and that should do the trick.
What I want to achieve: https://youtu.be/AgC2JLuG62U?t=137
but what happens in my game: https://streamable.com/2w75mu
to give more details this is how the hierarchy looks and the inspector.
https://prnt.sc/1s61vp7 https://prnt.sc/1s61xja https://prnt.sc/1s61u3q
in the script I just change the source object weight to make it appear at back of character. if I put the "weaponOnBack" outside of character's rig then the weapon doesn't rotate and that "going through character" still happens.
p.s.: in the screenshot, both multi-rotation and position are 0/off.
As I said, your weapon should be placed outside of your rig hierarchy so it won't be affected by the position and orientation, See Multi-Parent Constraint. Rather than adding the weapon directly as a child to the pivot gameobject, create a proxy gameobject outside of your character's rig hierarchy, add the multi-parent constraint component to it and constrain itself. The source object should be your weapon pivot and as you had, turn off the Maintain Offset. It should work Edit: forgot to mention that your weapon should be a child of the new constrained gameobject we've just created
Your answer
Follow this Question
Related Questions
Stopping navmesh agent next to the enemy 0 Answers
Rigidbody slows down before touching its target 1 Answer
focusing on a unit during unit detection in an RTS 1 Answer
Move object towards an angle the distance of two points 1 Answer
Help Calculating Shortest Total Distance Travelled By a Combination of Objects 0 Answers