RigidBody becomes awake without a collision
I have a ball object with a RigidBody that is initially asleep and the ball is floating in the air. I want the ball to become awake when a player object touches it (which I thought was a default behaviour). Instead, the ball gets awaken if a player gets close to it, but still without touching it. How can I prevent this from happening? I checked the OnCollisionEnter() method and it's not called when the ball becomes awake. It gets called when an actual collision happens.
Answer by MelvMay · Apr 01, 2017 at 10:48 AM
So you're talking about 3D physics then. In-case you're not using 3D physics, know that 2D physics wakes objects when their AABB overlap and not when they collide. Unity uses Box2D for 2D physics and this is fixed behaviour. You can visualise the AABB of colliders by going into 2D physic settings, opening "Gizmos" and checking Show Collider AABB property. When BoxCollider2D are not rotated, their AABB are perfectly aligned with the collider however if they rotate you'll see they are not. For other colliders, the AABB never aligns perfectly with the collider.OnCollisionEnter()
Thank you for a helpful answer. I turned on AABB gizmos, but they don't seem to overlap at the moment when the ball becomes awake. I'm attaching a screenshot. Perhaps objects become awake even sooner. I should probably try to make the ball float in some other way and then detect a collision to unlock it.
I can assure you, 2D physics wakes objects when their AABB overlap or if you perform an action that modifies the body in any way.
The image doesn't help at all because there's no description on what it is supposed to show.
The image shows a player (the red blob), a ball and their AABBs that were turned on in the 2D Physics settings. It's more or less the moment when the ball becomes awake. The blob jumped up from the ground that's below.
Your answer
Follow this Question
Related Questions
Collision sticking? 1 Answer
Rigidbody2D and non-trigger child colliders! 2 Answers
Adding force to a rigidbody opposite to the direction of a rotating weapon 0 Answers
Rigidbody rotate velocity 0 Answers