Very weird position "snapping" with simple box colliders? - unity3d

Im not even sure what is happening here but I'm just trying to make objects fall normally onto the floor - they need gravity/be able to be pushed around, but just fall onto a static floor object.
I have a cube and my floor mesh. Floor mesh has this:
Cube has this:
Initially I'll have my cube just positioned right over the floor. Then I press play and pause, within one second it's 100 m away, spinning/falling. What could be happening here?

You may face problems with small size colliders due to how the physics engine works. Increase size of colliders and see if it helps. If you really need colliders this small, try changing the Default Contact Offset in Physics Manager.

Related

Unity - How to give some flexibility to colliders

Hi I'am new to Unity and I was trying to implement a game using tetris blocks.
The game's goal is to build the highest tower before it collapses. However there is a problem in my implementation which is seen in the picture below.
I achieve the building a tower task by activating the rigidbody gravityscale when it collides with something. With that way it can collapse after touching somewhere not before. But I want to have the flexibility of some collisions. In the situation seen in the picture below, that 'T' block will collide with the point in the red circle before landing safely and gravityscale of the rigidbody will be set. So it will drop but I don't want it to happen becasue the collision area is too small. I want to make it land safely with some flexibility.
I tried to make colliders' size 0.9 but that just disrupts the scale of the world.
Can I do something like this :
If collision happens, check collision area and if the area is lower than lets say 0.1, do not trigger rigidbody gravityscale.
what about using capsulle collider 2D with small radius?

Objects not colliding Unity2D

I am trying to make a Retro Tenis Game in Unity2D but I have some issues with the colliding system.
My controller does not collide with the walls. It goes through them.
It should stop in the wall like pic1 but it goes through it like pic2.
Can anyone help me, please?
pic1
pic2
UPDATE#1: I added a RigidBody component but it does not fix it. (pic3)
pic3
You shouldn't use the colliding system for this purpose. It would be much better that the script in charge of moving your paddle was able to control its maximum and minimum height too (note that the screen size can change, and the paddles should move at different heights depending on the screen size).
Although if you want to do it with the collision system and "walls" that limit the space of the paddles, both the "walls" and the paddles need to have a correctly positioned BoxCollider2D and the paddles an extra kinematic Rigidbody2D too (as they can move).
Also make sure to move the paddles using physics and not modifying its position with transform.position (see Rigidbody2D.MovePosition)
Edit: Unity2D physics system is rather a complicated topic and difficult to get it well on your own. I'd suggest to learn the basics in the Unity Learning Platform. You could start with this project.
You need add RigidBody2D to your "circle"

How to make Quads flush with each other

I'm making a game where I move a red cube across a plane with arrow keys (I am setting the velocity in order to get a constant speed) Here is a preview:
game
Currently, I am just using a plane with a grid material/texture. However, I wanted to change one of the tiles in this grid to a different color and detect when my cube passes over it.
My idea was to simply replace the plane with a bunch of quads. However, when I do that and try to navigate my cube across the quads, it seems to collide with the side of the quad and flip up, despite the fact that they are all at the same height and positioned right next to each other.
Is there a way to make the quads flush so when I push my cube over it, it won't collide with the side of the quads? Is there a better way to create this behavior?
You can disable colliders at this quads and add invisible big plane with collider

Unity3d - Player flips after a specific chunk

So, I've made a very simple game, which all you basically do is glide through the terrain and avoid the obstacles (I haven't implemented obstacles yet). And I've encountered a very strange problem. When ever I hit the fifth chunk, the player starts to flip:
Can anybody help me find what the problem is and how can I fix it?
Edit: I solved it by using creating a physics material with 0 friction annd applied it to both the chunk and the player.
This could be an issue with your colliders being just a tad too big. check the dimensions of your player's box collider and see if it is bigger than your player. If so make it fit to just inside the outer edges of the player box. Also, unless you ever plan to flip the player intentionally, You could always just apply a constant downward force (Rigidbody + gravity usually will suffice) to keep this from happening. Hope that helps!

Unity Brick Breaker: Ball hitting in-between two bricks

I am making a 2D Brick Breaker game in Unity.
I have an issue with the scenario when ball hits in between two bricks. I have BoxCollider2D attached to all bricks and a CircleCollider2D attached to the ball. When the ball hits between 2 adjacent bricks, it bounces back in the same direction as if it hit the edge of the brick. There is no edge in between, but two adjacent bricks form a continuous surface. So, the ball should bounce off of the surface (in other direction) instead of bouncing back.
Anyone knows of any solution to tackle this problem? I asked this in the Unity Physics forums but didn't get any answer, so checking if anywhere here might have had this issue.
Thanks,
Mukul
I am guessing this could be the problem:
When your ball is hitting the bricks with a strong force, There is a chance it might move one of the bricks by a very very slight distance, even if the mass of the brick is much heavier.
This movement might cause an uneven surface, which is why the ball bounces back in the same direction.
Try adding a Rigidbody Component on every brick (if you have not done it already), and set its isKinematic property to true.
Let me know if this solves it.
Way 1:
Use one box collider for the wall, but not for every single brick.
This will fix your issue + will optimize your project.
Way 2:
You need to build wall programmaly and colliders in this case must be without spaces between them. This must fix the issue.
Way 3:
Make your own hitting wall logic.
OnColliderEnter you need to get balls velocity.
OnColliderEnd you need to set manually velocity.