x


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

more ▼

asked Oct 13 '11 at 07:45 AM

Uniquesone gravatar image

Uniquesone
86 9 14 14

In a word: by making it a child of the object it has "stuck" to. Manipulate the parent/child chain to achieve the sort of paradigms you describe.

Oct 13 '11 at 11:23 AM Fattie
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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
  }
}
more ▼

answered Oct 13 '11 at 08:07 AM

aldonaletto gravatar image

aldonaletto
41.3k 16 42 195

Nice, thanks alot

Oct 13 '11 at 09:41 AM Uniquesone
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5059
x2485
x1683
x65

asked: Oct 13 '11 at 07:45 AM

Seen: 1389 times

Last Updated: Oct 13 '11 at 11:23 AM