- Home /
Sphere sticks to cube
The problem: why does my sphere stick to the lower border after bouncing from the right border?
This problem always happens when ball.rigidbody.velocity.x != 0
.
Update: I created a workaround which is shown below.
This is my simple scene (I removed all other parts to ensure that the bug doesn't relate to my code):
My Physic Material which I applied to both cuboids:
Dynamic Friction: 0
Static Friction: 0
Bounciness: 1
Friction Combine: Minimum
Bounce Combine: Maximum
Friction Direction 2: 0, 0, 0
Dynamic Friction 2 0
Static Friction 2: 0
I also created a behavior for the ball which basically sets rigidbody.velocity
to an initial motion vector (say 3, -1, 0
).
My workaround:
Vector3 velo = rigidbody.velocity;
string[] applicableBorders = new string[]{"BorderTop", "BorderBottom"};
if (velo.x == 0 && System.Array.IndexOf(applicableBorders, collision.collider.name) < 0) {
rigidbody.velocity = new Vector3(rigidbody.velocity.x, rigidbody.velocity.y * -1.0f, rigidbody.velocity.z);
}
I wonder whether any cleaner solution exists.
I don't quite get what is your problem. The ball sticks to the bottom border but it has rigidbody so gravity pulls it downward where the lower border is. Could you explain further?
Answer by ComFreek · Jan 24, 2014 at 02:23 PM
It works now.
I only removed my code - nothing else. That's really strange because it hasn't had worked before without the code.