How to change collider in individual tile in tilemap - unity3d

I am using tilemap in unity for level building. I need colliders on my tiles. If I add a tilemap collider to the tilemap it generates a collider around the tile, however I need to edit these colliders and have different colliders for every tile.
How could i do this?
Wrong collider:
What i want to achieve:

In your case you have square tiles and the Tilemap Collider box fits it naturaly.
To edit the Tilemap Collider, go to the Sprite Editor in the Sprite you're trying to use and modify how you want it to by clicking in Custom Physics Shape
Then, once you have the right shape, reset your Tilemap Collider and you're good to go.

Updated Answer for newer versions of Unity 2019+:
You now have to open the sprite sheet in the sprite editor and then select "Custom Physics Shape" under the Sprite Editor dropdown.

Your Sprites usually automatically generate a physics shape. You can use Unity's physics shape editor to modify your sprites generated physics shape. With this, you could modify each tile's automatically generated shape. If you're looking for a more tailored shape that is more specific than just the sprite, you may need to build custom colliders that are not tied to your painted tilemap.

I've discovered "PolygonCollider2D" which allows you to make a more precise collision shape. I've made the collisions as a separate Game object.

Related

How to create a collider with a physic friction for a racing track in Unity

I will briefly explain the problem.
I am developing a racing game and I wanted to know how to add some friction to my track.
I tried to add a terrain collider with a physics material to the track mesh but it doesn't work.
I am also very confused about how to add a collider to the track that respects its shape.
Thank you all in advance
You can use a MeshCollider component and add it to the track, this will form a collider around your complete mesh.
https://docs.unity3d.com/ScriptReference/MeshCollider.html
You could then apply a PhysicMaterial component to the track or your car(s) (you can add it to the collider). I believe a rigidbody component should also be added to the car, so that it can move with physics.
Mess with the values and read the docs:
https://docs.unity3d.com/Manual/class-PhysicMaterial.html

Specify walkable area in Unity 2D

I want to limit the area where my player can walk. In this case only on red segments.
And I want to use 2D sprites as background images not 3D models. But my main player would be in 3D
Can I use NavMesh here? Or should it be done with Tilemap? Or should I place some 3D objects above it?
here is another scene that I would like to understand how to build
You can try adding invisible colliders attached to an empty gameobject to prevent your character from walking into certain areas.

Collider for blender pot model inside Unity

i've made a simple pot model inside blender:
So the idea is that after importing to unity, generating mesh collider, adding ridgin body i would like to be able to put smothing inside the pot. Now it's generating collider but without a "hole" inside, so if i throw smth inside it just bounce off the top. Is there any way to do it simple way? I'd like to avoid making a collider by hand in unity, using cubes and so...
Image overview:
Your collider needs to be concave
It isn't clear from your question how you're "generating mesh collider," but the results are clearly generating a convex collider.
That said, some things to know about mesh colliders (and concave ones even more so): They are very compultationally heavy to calculate, so they should never...
move
scale (especially non-uniformly)
rotate
...at runtime.
Alternatively you can use multiple box colliders in the same orientations as the side-segments of your can (along with one or two for the bottom, depending on how small of an object you'll be dropping inside).
Uncheck the generate collider box from the import settings, add a mesh collider component and check convex.
I would use four or six box colliders for the walls of the pot and another for the floor. You can scale each box collider along each axis, but if you want to rotate a box collider you will need to give it a parent and rotate the parent. Box colliders are very low cost for the physics engine compared to mesh colliders.

Blender to Unity: Add Custom Collider to A Low Poly Style Terrain

I have created a low poly terrain object from Blender using a Plane, displaced and decimated it. I then exported it to Unity as an FBX object. As what I expected, my player simply falls through it since it has no colliders on. I could place a Box Collider on the object, but seeing it is a low poly style terrain with lots of bumps, it'll be pretty awkward to have my player walk straightly even if the ground is slightly raised. Even so, there are mountain areas in my terrain object and box colliders would totally be out of the question.
I was thinking of using the Mesh Collider in Unity. I tried experimenting with it but failed. There are also no clear tutorials online on the said situation. How can I add a custom collider to this terrain so the player can walk to it, plus without using the hastly Box Collider.
Here is my terrain object in Blender:
As you can see, putting a box collider is totally impossible.
You can make individual Sphere, Capsule and Box Colliders, hide their Mesh Renderers and then rotate, scale and place them to make something similar to your mesh. However, Mesh Colliders should be your best option, after adding a mesh collider to your mesh, make sure the convex option is NOT checked and also make sure to select the same mesh that the GameObject is using from the Mesh field in the Mesh Collider component.
Alternatively, if you want your collider to be simpler than your actual mesh, you could make a simpler mesh (either with an external program or by downloading the ProBuilder package in Unity), overlay that mesh with the terrain you have, give it a Mesh Collider and then hide its Mesh Renderer component.
I don't exactly understand what you meant by "I tried experimenting with it but failed." Did your character keep falling through? Did the character get stuck? Was the mesh collider generated in an incorrect way? I would be able to help you better if you can give me a detailed explanation.

Rigidbody between two terrains getting dragged to the upper one

If a rigidbody is below a terrain it is getting dragged up on the terrain
I have 2 terrains, one over another to make a cave like shape. If I put a rigidbody on terrain below it is getting dragged onto the terrain above. So i cant even put a single rigidbody inside that cave.
I tried with mesh collider on terrain obove instead of using terrain collider. But terrain does not have an actual mesh, so it didnt work.
Is there a solution to overcome this?
Since Unity's TerrainCollider is height-map based, you can't put one on top of the other and expect proper collision detection.