Colliders not working in Unity3D 2D Project - c#

I have 2 colliders, its a game where I have a ball, and a Labyritnh. The ball should pass through the labyrinth and collides with the labyrinth's walls.
But I have a problem, the physic aren't working that well, the collider don't work.
I have a rigidbody and a collider in both of these objects.
Also, I have a problem with choosing box or edge colliders.
Because it is a labyrinth, I need to design the colliders with some complex shapes.
I have used edges colliders and box colliders but the ball is passing through all these colliders like nothing, It seems like its not working.
Can someone help me?

you need a rigid body object attached to at least one of them for the colloders to work.
make each wall individually and use rectangel colliders. add a rigidbody component, and set that rigid body to kinematic. should work then.

Related

How to prevent character from going through walls. Unity

I'm new to unity here and I have a capsule for a player and a moving wall. When ever the player touches the wall, it can just go through and walk out the other side, and I kind of don't want that. The screenshot below demonstrates what I mean.
Player in moving wall
I tried to use rigid body and collisions to help give me a solution, but that didn't stop the problem. I'm now not really sure what the best thing is to do.
Rigidbody should be able to do the trick. You said that it did not work, so here are a few things you need to make sure you have done for the Rigidbody collisions to work properly:
Give the player a Rigidbody component
Give the player a collider (best use capsule collider)
Give the wall a collider (it looks like a box collider would work best)
When you move the player, move them with the function Rigidbody.MovePosition(newPos) or by setting the velocity with Rigidbody.velocity = new Vector3(newVelocity)
The "Is Kinematic" checkbox of the player's Rigidbody component is un-checked (set to false)

Unity3D Rigidbodies acts like objects is elastic and falling inside eachother

I was making a game about stacking objects on top of eachother but when I spawn a new object above it falls inside in other object and behaves like elastic material.
I didn't specify any Physics Material to the Rigidbody, It's just a vanilla Rigidbody component.
Here is a gif about my problem
You might have forgotten to add a Box collider to the cube prefab.
Make sure that the collision detection method on the rigidbody is set to either continuous or continuous dynamic. Make sure there's a collider as well.

Avoid the character jumping because of capsule collider

My unity game have a character with a capsule collider. When the character hit another collider on the spherical part of the capsule, the character is send in the air. How to avoid that?
Here is a video to explain the problem
I already have some solutions but it doesn't really work:
Use a cylinder collider instead of capsule, but it doesn't exist. I tried to make one with meshcollider and the result is not as good as a caspule collider since the meshcollider is not perfectly rounded. I also tried to make one with many rect collider but it produce same problems as meshcollider.
Set a really big gravity force when the character is on the ground, but the problem is that I have inclined planes in the game, so it doesn't work neither.
Thank you for your help
I might not be right but I think you should delete the capsule collider and add a Mesh Collider or you could also just add colliders to each part of the player which would take longer but I think that's what you're needing. So add sphere colliders to the head, box colliders to the arms and etc.
You can propably fix the unwanted behavior:
with a different physics material for your colliders. Removing bounciness may help.
by adjusting scales of your objects.
by changing the collider of the ground from a box collider with sharp edges to a mesh collider with slopes on the edges.
by adding a code that will snap your character to the ground.
There is a great tutorial on character movement from Catlike Coding I can recommend: A series about controlling the movement of a character.

How do I stop objects from Overlapping in Unity?

when my objects spawn into world they can move around each other. The only problem is that they can overlap when they move, i.e the sprite of one object moves onto the sprite of the other as show below:
http://prntscr.com/np1hs4
How would I be able to avoid this?
Check if colliders are trigger or remove all components from gameobject and just leave only rigidbody and colliders. Rigidbody and colliders should be of the same type rigidbody 2d collider2d. Hope it helps!

Collision between Box Collider 2D and Polygon Collider 2D not working

Currently I am working on a networked 2d platform game.
My player is an empty object which serves as a parent to my actual graphics etc. The empty object has a rigidbody (3d) attached to it as it needs to have one in order to use the configurable joint component ( note: I move my player around using this 3d rigid body).The player body however, a child to the graphics, has a box collider 2d attached to it as it after all it is a 2d game and has to collide with other 2d objects.
My platforms have polygon collider 2ds attached to them (which is connected to a platform effector if that is worth mentioning).
Now, even though both my player body (which is a child to graphics which is a child to my player object) and my platforms have 2d colliders on them they do not collide and can simply go inside each other (neither of them is marked as isTrigger).
In order to solve this I thought I would add a rigidbody 2D to the player body and see if that would do anything. Now upon adding the rigidbody 2D collisions did work but as soon as I made the rigidbody 2D have all position and rotation constraints ticked or as soon as I made it kinematic or static it would cease to collide with my platforms. The problem is I need to have the rigidbody 2D be static or not be able to move as I am currently moving my player object using the rigidbody (3d) attached to it and do not want any additional movement of the player body upon colliding with objects.
I know this is quite a lot of information, so if you have any questions or would like further information just comment and I will be quick to respond. Thank you :-)!
Edit:
2d ray casts are also unable to hit the player body box collider 2D
Edit 2:
So to recap:
If either the player body or the platform has a rigidbody 2d that is not static (dynamic) and can move collisions work. However currently I only have a rigidbody 2D on my player body which has to be static though (as explained earlier) as well as a box collider 2d. My platform(s) on the other hand currently only has a polygon collider 2d as I do not see why it would need a rigidbody 2D.
A static collider won't detect the collision with another collider if it doesn't have a rigidbody, if it is static or if it has a kinematic rigidbody. At least one of your two objects needs to not be static and to have a rigidbody which is not kinematic to be correctly detected. So you do need to add a Rigidbody2D to your platform.
When you have a doubt about why a collider wouldn't collide with another one, always refer to this page of Unity's documentation which sums up which kind of collider will collide with another one.
Rigidbody2D can't collide with Rigidbody3D, here's a workaround though
http://answers.unity3d.com/questions/580769/can-rigidbody-2d-collide-with-3d-colliders.html

Categories

Resources