Unity2d TilemapCollider2D not generating collider for certain sprite images - unity3d

This specific purple colored image with a bit of opacity isn't getting a collider generated around it by TilemapCollider2D
I've tried setting the same settings as the other sprites that don't have this problem but nothing happened. This is also in a brand new project that I've created to test this collider generation only. Everything else is default settings.

TilemapCollider2D relies on a property called ColliderType to determine what shape to draw a collider. Check your collision tile file’s properties, and see if ColliderType is set to None. If so, you can change it to either Sprite or Grid, and it should draw the collider.
For more info:
https://docs.unity3d.com/ScriptReference/Tilemaps.Tile.ColliderType.html
Hope this helps.

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

Player falls halfway throufh the floor till the outer edge of collider. instead of the inner edge

As you can see in the included video the player falls over the floortile till the outer edge of the floor. Instead it should stop at the inner edge of the tile so it looks like its standing ontop of the tile. Can anyone help? I cant find anything on the internet regarding my issue.
Im sorry if this is a easy fix. Im a beginner. This for a school project :)
Video: https://streamable.com/99jz2o
enter image description here
Photo of sprite standing on the wrong edge of the tile.
Edit: I went back to the tile palette and redrew the level. This time selecting the game object + bitmap again. Now it works. Probably the reason why it didn't work was that when I drew the level I had not added Tilemap Collider 2D and Composite Collider 2D. Now redrawing with those 2 components added it works as it should!
The problem is with your tile map collider. Instead of using this, set empty game objects as children of the objects that make up the . Then, add BoxCollider2Ds to each one, and add scale them to fit the map. If that doesn’t work, then it is either a problem with the rigidbody, or the box collider, make sure that all of the settings are set to default, then slowly change them back, and you will discover what is causing the problem. Then you can comment on this post what variable changed it.
Your issue is the Composite Collider. The docs specify that they
do not define an inherent shape. Instead, it merges the shapes of any
Box Collider 2D or Polygon Collider 2D that you set it up to use
When you attach a BoxCollider2D or PolygonCollider2D, there is a check box on them that specifies Used by Composite. When checking this box, other fields will disappear as they are now controlled by the CompositeCollider.
To use this collider, make a new object that will hold all your other colliders or make a few that hold sections of your map. Give this new parent object a CompositeCollider2D and give all the children BoxCollider2D or PolygonCollider2D. After this, make sure to check the box Used by Composite on the children Colliders.
Edit: Sorry just saw you were using a Tilemap. Just make the CompositeCollider a parent of your Tilemap while keeping the Used by Composite checked.
Edit 2: I am not too familiar with Tilemaps with Composite Colliders, but one other solution you can try before re-childing is changing the Geometry Type field on your CompositeCollider from Polygons to Outlines.

If I disable object mesh renderer will it affect anything wrong?

I have a Sphere that is a child. The problem is that in the game I see it in front of the camera and I don't want to see it but still want to use.
If I uncheck and disable the Mesh Renderer component it might make the Sphere not working as what it needed for ?
No. The mesh renderer only draws the object in the scene, if it's disabled it will stop drawing it. Everything else will still work: if it has a collider it can collide or be clicked on, if it has a rigid body it will have certain physical properties, it will be found if you call Object.FindObjectOfType(), and so on.
Now it's a different story if you disable its game object.

How to change collider in individual tile in tilemap

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.

Why the info panel of collider is grey in unity3d?

I added a collider2D component to my Player to collide with the floor, but I noticed that the info panel which contains physic parameters like Friction, Bounciness is grey.I have to create a physics material by myself.So is that what it is(read only)?
image
Those values there are only readable and not able to be written on or to be changed.
Therefore if you would like to change them you need to make a PhysicsMaterial2D and apply it to the CircleCollider2D. You can also change the extents and centre of the CircleCollider2D by referencing the component in a script.
https://docs.unity3d.com/ScriptReference/CircleCollider2D.html