- Home /
How to detect CompositeCollider2D shape center?
I'm using composite collider 2d as triggers in my tilemap to define ladders. The problem is trying to get data on the specific ladder I am colliding with. I need the x value of the ladder's center so I can center the player while climbing.
I would normally use the Collider2D in OnTriggerEnter2D and use the bounds to determine center of the ladder, but with using the composite collider, all the tiles in the tilemap are used to determine bounds.
I think the solution must have something to do with 'shapes', because when I debug collision.shapeCount it gives me the right number of chains (2 in the example case)
void OnTriggerEnter2D(Collider2D collision) {
if (collision.transform.CompareTag("Chains")) {
Debug.Log("n of chains: " + collision.shapeCount);
//Debug.Log(collision.bounds.center); - nope
//Debug.Log(collision.composite.bounds.center); - nope
BeginClimb();
}
}
So, is there a way to get data on the specific single ladder 'shape' collider that we are hitting and not the entire tilemap object?
Thanks!
Your answer
Follow this Question
Related Questions
Better Tileset Collider 2D 0 Answers
Player Gets Stuck On TilemapCollider2D 0 Answers
Spawning prefabs randomly on top of existing tiles 2 Answers
Tilemap Collider 2d bumps and walls 0 Answers
tilemap collider2D is it possible to "walk" inside composite collider (pictures to explain) 2018.1 0 Answers