- Home /
How do I add force to rigidbody when raycast hits it.
I have an enemy (named "Peeker" in the code) fully rigged, with each child being a certain bone. I am trying to make it so that once you shoot the enemy's bone with a raycast, (which I have already programmed successfully) it applies force to whatever bone it hits.
Here is my code so far. As you can see I tried to use "rigidbody.Addforce(-transform.forward * 500); " under the public void "takeDamage," but it gives me a red line.
(btw if you are wondering why the script is called "Peeker_instakill," it is because this script only gives the peeker a health of 1 if you hit this specific bone, making him easily killable for headshots.)
capture.png
(42.1 kB)
Comment
Answer by KittenSnipes · May 20, 2018 at 10:53 AM
@b2hinkle Try that
Peeker.GetComponent<Rigidbody>().AddForce(-transform.forward * 500);