Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

How to get Animator.GetBool to work as a parameter in OnCollisionEnter in Unity (c#)?

$
0
0
I have a small amount of coding knowledge but I can't seem to wrap my mind around why this isn't working. Here is the code: public Animator animator; public float forceApplied = 50; private void Start() { animator = GetComponent(); } void OnCollisionEnter(Collision col) { if (animator.GetBool("PunchTrigger")) { if (col.gameObject.tag == "Boss") { col.gameObject.GetComponent().AddRelativeForce(Vector3.back * forceApplied); } } } This is attached to my players hand with a sphere collider attached. While the "PunchTrigger" animation is playing and if the hand collides with the character tagged as "Boss", it should push the object back, however, nothing happens when I play the scene. The code works fine without the animator.GetBool("PunchTrigger") and the void Start() though.

Viewing all articles
Browse latest Browse all 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>