Specify walkable area in Unity 2D - unity3d

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.

Related

Unity: opaque area of image should be a collider, transparent area should not

I'm fairly certain that I search every possible answer for this, so please forgive me if there is an answer somewhere...
I have a bunch (35) images that are procedurally assembled to make a "maze" of sorts. The "player" object is placed in a random position on the screen and I it should avoid the collidable space. The "maze" images are 2D with some opaque areas (white) and transparent areas (blue). In Unity, all of the images have Polygon Colliders that are using Composite... All of this works perfectly, except...
My issue is that Polygon Colliders use outlines or polygons, but everything in between is not a collider. That means that, unless the player hits one of the edges of the collider, it won't register an actual collision.
To better understand this, look at the image. The player will spawn in the opaque area of the image, when I want that area to be a collider.
Btw, not using Composite produces the same issue, where the player object spawns between the polygon edges.
Any idea how to make the entire opaque area a collider?
You can check for a collision within the collider by using the void OnCollisionStay2D(Collision2D collision) method for whichever object that you want to handle the test.
However, if you're trying to use the collider to determine whether an area is safe to spawn in, you might want to check whether the spawnpoint is inside the collider using collider.bounds.Contains(player.transform.position) (or whatever position you'd like to check).
Check the documentation for more info: https://docs.unity3d.com/ScriptReference/Bounds.Contains.html

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.

Unity3d Is there something like Mesh Collider for 2D objects?

Im making simple 2D game, I designed the "way" the player going through in the game.
If the player touches the wall the game is over, so I must detect collisions.
At first I created the walls from sprites, but then I realized there is no 2D collider that suit himself to the shape of the sprit(it was to difficult to create the collider manually from a lot of smaller polygon and circle colliders), so I made all the walls that builds the "way" 3D objects(.dae files with z=0.001), and added them the mash collider which suits himself to the 3D object. I changed my player to be 3D as well so the collisions types will match.
It worked, but I'm sure the same game can work by much better performance with the same resources if all the game objects were 2D.
How can it be that there if a collider that suits himself to a 3D object but there is none for 2D?
Maybe I miss something?
At my first attempt I didn't export the sprite correctly so the polygon collider didn't recognized the shape of my sprite.
I export the sprite as JPEG, when I export it as .png it worked like a charm, just added the Polygon Collider and it match to my sprite shape perfectly, thanks!

How can I make custom 2D polygon in Unity with collision detection?

I am learning Unity and I want to make a little game where the user controls a tank and she can shot with it. My plan is when the missile hit the terrain, it makes a hole in that, like in the old school Worms. My first idea was to make the terrain as a textured polygon and when a collision happens, change the polygon structure. Is it possible to implement this?
You can do a little trick with a 3D mesh. If you are using orthogonal camera the Z axis won't be visible and you will be able to add mesh collider. If you still want to do custom things with that mesh like changing shape there are assets on the store:
http://u3d.as/content/chris-west/mega-fiers/1Qa
Or
When a missle hits terrain change you terrain texture pixels alpha channel to 0
http://docs.unity3d.com/ScriptReference/Texture2D.SetPixels.html
Then use raycasts to check if alpha channel != 0 for moving.

Unity3D Repeating pattern applied 2D Mesh with collider

What is the proper way of creating 2D Mesh with collider?
All I want to do is create some shapes (not very simple like triangle or rectangle) like slide or rounded rectangle. And I want to define a repeating pattern inside it to fill and reduce memory. Lastly I will need a collider around my shape.
Create the entire thing in a modeling program like Blender... same as you would for a 3D model, but all of your shapes/meshes will be flat. Create your textures the same also... all in your modeling program. Then save your file (.blend for Blender) to your Unity assets folder. Now switch back to Unity and drag/drop the prefab that is created form the .blend file on to your scene. Change the renderer if you want (I use Mobile Unlit, or Unlit Transparent most of the time).
Works just like a normal 2D sprite now... but the texture will repeat and you can make whatever shape you want in your modeling program.
For the collider, you can add any type of collider you want. If your shape isn't standard, you'll probably want an Edge Collider 2D or a Polygon Collider 2D.
I would suggest you the following:
Create a polygonCollider2D directly in unity as you need it
Add a mesh filter and a mesh renderer
Add a custom script made by yourself, in which you convert the Collider polygon to a mesh (Mesh that will be used on your MeshFilter at runtime).
3.1. In order to do this, just copy the vertices of the polygon
3.2. Use the triangulator class in this link to help you create your mesh (http://wiki.unity3d.com/index.php?title=Triangulator)
Enjoy
If you want to see the custom script find it here: http://answers.unity3d.com/questions/835675/how-to-fill-polygon-collider-with-a-solid-color.html