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

Knockback/Push back on Enemy by attack won't work correctly

$
0
0
Hey everyone, I'm trying to solve this issue since nearly 6hours without any success.. I hope someone can help me, I tried to use AddForce on a GameObject (Enemy) to push it back by hitting it, the following script is implemented in a Knockback Class which is attached to the enemy but when I hit it, it get's teleported and don's "slide" to it's position I hope this time someone help me, never got an answer to any of my questions... =( public Vector3 moveDirectionPush; public Rigidbody2D EnemyRigidbody; void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Enemy") { moveDirectionPush = EnemyRigidbody.transform.position - other.transform.position; EnemyRigidbody.AddForce(moveDirectionPush.normalized * 300f); //damage dealing and effects } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



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