Question by
Creative Inventory · Dec 19, 2015 at 12:42 PM ·
2dscripting problemcollidernot working
My knockback script is not working
My code doesn't work. When I collide with an object nothings really happening, I made sure that my objects box collider is checked to isTrigger, and I also increase the explosionStrength. What am I doing wrong could anyone help?
public class Knockback : MonoBehaviour {
public float explosionStrength = 10.0f;
void OnTriggerEnter2D (Collider2D target_){
Vector3 forceVec = -target_.GetComponent<Rigidbody2D>().velocity.normalized * explosionStrength;
target_.GetComponent<Rigidbody2D>().AddForce(forceVec,ForceMode2D.Force);
}
}
Comment