- Home /
Get the position of the particular tile involved in a TileMapCollider collision?
Hi there,
I'm working on a 2D platformer where ease of workflow is very important to me. I think the Unity TileMaps together with TileMap Colliders system is great and I would love to use them.
I am looking to implement ladders in my game - whereby the player will lock on to the ladder's x-position if she is climbing one.
Currently I have a TileMap specifically for ladders with a TileMapCollider2D attached, and "Is Trigger" is checked.
Currently what I need is a way to get the position of the particular tile the player is colliding with when this OnTriggerEnterEvent
is fired.
void OnTriggerEnterEvent(Collider2D col)
{
if (col.tag == "Ladder")
{
// Get the ladder's position
ladderPosition = ...
}
}
Later on then,
if (IsClimbing)
{
// Lock onto the ladder's x-position.
transform.position = new Vector3(ladderPosition.x, transform.position.y, transform.position.z);
...
Is there a simple, out-of-the-box approach to getting the position of a colliding tile? Note: col.transform.position
will just return (0, 0, 0)
because it is getting the position of the overall tile map. I am seeking the position of the particular tile in the map which my character is colliding with.
I'm also open to alternative suggestions, but keep in mind: I want the level-designing workflow to be as easy as possible because I am working on a game that will potentially have hundreds of levels.
Your answer
Follow this Question
Related Questions
Collider that restarts the game? 1 Answer
Player Gets Stuck On TilemapCollider2D 0 Answers
OnTriggerEnter Getting called more than once. 0 Answers
Can't click gameobject when over another trigger? 1 Answer
Making Sprite Disappear on Trigger 2 Answers