- Home /
2dToolkit and Physics2D.OverlapCircle
So, I picked up Unity with the 4.3 release and have only just started to make some things move around, jump etc. I had a simple piece of code to check if the player is grounded:
grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
It works great on a bog standard cube with a collider and layer set.
To get things moving I decided to buy 2dToolkit, mainly for the tile mapper, because IMO it's really tedious aligning sprites and drawing out levels in the current release.
I drew out a simple level, just a platform with a collder, set it the tile map layer [Tk 2d Tile Map (script) layers - > ground] BUT "grounded" never returns true. If I do the same thing with a cube and add it to the "ground" layer, no problem, it's just the tile mapper that doesn't seem to work.
sorry I know its a convoluted question. But if anyone with any experience could help me out I'd be grateful.
Answer by JakeTBear · Mar 25, 2014 at 01:40 AM
This was a known bug, the 2D toolkit creates Edge colliders which are currently not responding to manual checks such as Physics2D.OverlapCircle.
http://forum.unity3d.com/threads/213191-Physics2D-Overlap-Circle-not-working-with-Edge-Collider-2D
I'm glad it's not just me. I was really frustrated buying 2Dtoolkit to get moving quickly only to run head first into this problem!
Answer by leebs0117 · Mar 07, 2014 at 12:24 PM
I add a Circle Collider 2d on Player and write OnTriggerEnter2D() in Script
public void OnTriggerEnter2D(Collider2D other)
{
if (((1 << other.gameObject.layer) & whatIsGround.value) > 0)
{
grounded = true;
}
else
{
grounded = false;
}
anim.SetBool("Ground", grounded);
// Set the vertical animation
anim.SetFloat("vSpeed", rigidbody2D.velocity.y);
}
Your answer
