Hey everyone.
I’m not one to ask questions, but I find this situation quite odd:
I have three Colliders2D with a rigidBody attached to all of them.
The Player
The Weapon
The Enemy (a Tree right now)
Situation 1:
The weapon collides with the Tree, the tree gets knocked back. - This Works!
Situation 2:
The tree collides with the Player, the Player gets knocked back. This Doesn’t…
Both the tree and the player have an OnCollisionEnter2D scripted that basically says the same thing:
TreeCollision:
void OnCollisionEnter2D (Collision2D coll){
if (coll.gameObject.name == "Player_Weapon") {
Debug.Log ("HIT BY WEAP");
isHit = true;
gameObject.GetComponent<MoveToPlayer> ().canMove = false;
dir = coll.contacts [0].point - (Vector2)transform.position; // contact point direction
dir = -dir.normalized; //to the opposite direction
myRigid.AddForce (dir * force);
}
}
PlayerCollision:
void OnCollisionEnter2D (Collision2D coll){
if (coll.gameObject.name == "Tree1") {
Debug.Log ("THE PLAYER is HIT");
direction = coll.contacts [0].point - (Vector2)transform.position;
direction = -direction.normalized;
playerRigid.AddForce (direction * force);
}
}
Why would the tree get knocked back by the weapon, but not the player when getting hit by the tree?(even when standing still).
Everybody is a dynamic rigidBody, and the debug log is showing.
Thanks for the help!