It looks like you're new here. If you want to get involved, click one of these buttons!
Hello Guys/Girls . I want to detect size of that tile (platform) under that zombie character with collision. so i can use its size for making patrols. can any one point me into right directions..?
I am using Unity 3d Engine 2020 and that Platform is a Part of Unity Tile Map.
Screenshot : -
Answers
Through its renderer, you can get a bounding box.
More info here: https://docs.unity3d.com/ScriptReference/Renderer-bounds.html
and here: https://docs.unity3d.com/ScriptReference/Bounds.html
To get the edge, I think you have to do something like:
This would give you the lower left corner as a Vector3. I do not know if this is in world or screen space though, so this next part you may have to experiment with. Basically to get the edge at the center of the road, you need to bump it up to the same Y as your zombie in this case. If it is a perfect, non-rotated rectangle, you could maybe get it by adding the difference of the max Y and the min Y.
Edit 1: Just checked the docs, the bounds are in world space.
Edit 2: Alternative solution, your zombie could check if it has reached the edge, by casting a ray down and in front of itself. If it collides with nothing, or something else like a barrier, you could turn it around then.
@Mouledoux thank you for replying but its part of Tile map not a standalone object.. ...thats what my problem is how to access single tile in a tile map...?
Then I would just go with my 2nd suggestion, and do a ray cast to check for colliders.
@Mouledoux means no chance for getting x and y size with bounding box :/
I actually don't know tile maps enough to say for sure. But unless you NEED the x and y size, I would just do a ray cast.
@Mouledoux Thank You :)