- Home /
Rigidbody and BoxColliders not colliding[RESOLVED]
I have 2 2D Sprites: An Enemy AI and a Player.
Player Components: Rigidbody2D (isKinematic) and BoxCollider2D Enemy AI Components: Rigidbody2D (isKinematic) and BoxCollider2D
The enemy sprite is programmatically moved by its rigidbody. I put a debug.log("Collided") call in the player's script under the onCollisionEnter2D function but they are still moving through each other. I checked their layer and their z position to double check if I pulled a wonky.
void onCollisionEnter2D(Collision coll)
{
if(coll.gameObject.tag == "Enemy")
{
Debug.Log("Ow");
}
}
Answer by Raresh · May 30, 2016 at 08:40 PM
One of the rigidbodies must not be kinematic. I think you want the enemies to move and the player to remain unaffected. Disable the isKinematic on the enemy see if that helps.
If isKinematic is enabled, Forces, collisions or joints will not affect the rigidbody anymore. The rigidbody will be under full control of animation or script control by changing transform.position. Kinematic bodies also affect the motion of other rigidbodies through collisions or joints.
Answer by Tabu · May 30, 2016 at 08:35 PM
I think you need to do this instead
void onCollisionEnter2D(Collision2D coll)
{
if(coll.gameObject.tag == "Enemy")
{
Debug.Log("Ow");
}
}
woops that is what I did i just typed it wrong in the question. Honest mistake
Your answer
Follow this Question
Related Questions
BoxCollider2D + Edge radius + use auto mass 1 Answer
Newest Unity version bug? (Unity 2019.3.0a4) 0 Answers
Player sprite clipping through game boundary in 2d scene 1 Answer
How do i make my grounded variable change as I hit the platform and as I jump? 2 Answers
How can I make two objects with rigid bodies that won't displace each other? 2 Answers