- Home /
How to make an arrow to become stuck?
Hello,
I have a bow and an arrow. I want to shoot the arrow at an enemy.
The enemy and the arrow have both a collider. But when the arrow hits the enemy it collide with the enemy and get pushed back.
So how to become the arrow to stuck in the enemy? (If also possible to control how deep the arrow will stuck?)
Thank you
In a word: by making it a child of the object it has "stuck" to. $$anonymous$$anipulate the parent/child chain to achieve the sort of paradigms you describe.
Answer by aldonaletto · Oct 13, 2011 at 08:07 AM
You could set the arrow rigidbody to kinematic to stop the physics movement, move the arrow a little forward to ensure it penetrated the enemy body, and make it an enemy child to join both. If you have a OnCollisionEnter function in the enemy script, you can use something like this:
var depth: float = 0.30; // how deep the arrow will enter the body
function OnCollisionEnter(col: Collision){ if (col.transform.tag == "arrow"){ // only arrows accepted col.rigidbody.isKinematic = true; // stop physics control col.transform.Translate(depth * Vector3.forward); // move the arrow deep inside col.transform.parent = transform; // stuck the arrow to the enemy } }
Just out of curiosity, shouldn't it be col.transform.Translate(depth * transform.forward);
instead of vector3.forward to make sure engine also considers the object's rotation?
Thanks for the help !
No, because Translate
already operates according to object's rotation.
I am using rigidbody to move around so I had to change my own. Didnt know that :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613005642im_/https://answers.unity.com/themes/thub/images/avi.jpg)