Question by
Kamcix · May 27, 2017 at 02:24 PM ·
c#scripting problemknockback
Script not working as it should
Hello. I found and wrote a knockback code applied to my cube (player character):
void OnCollisionEnter(Collision col)
{
float force = 10;
if (col.gameObject.tag == "Enemy1") {
Vector3 dir = col.contacts [0].point - transform.position;
dir = -dir.normalized;
GetComponent<Rigidbody> ().AddForce (dir * force);
print ("turururu");
}
Print works excellently, there's "turururu" in my console, but the knockback, independently of amount of force I put there, is not. Sometimes it happen that my cube is thrown out somewhere, but it's more like an accident thing, than the script work.
Where is the problem and how to make it work correctly?
PS sorry for my possibly mediocre english (and maybe asking dumb questions)!
Comment
Answer by ChristosKapenis · Jul 03, 2017 at 08:01 PM
The force should be bigger. Try something like 500.
Your answer
