OnCollisionExit2D Issue

I am having an issue I don’t understand. I have an object that moves. When I jump on it it adds its velocity to mine so that I don’t fall off. Works great. Problem is it wont detect the collision exit when I jump off… The script is on the platform. it has a boxcollider2d on it and also on my player with a rigid body. The exit works for my terrain but that is scripted on the player. Not sure if that makes the diference. Anyways when I leave contact with the platform should it not fire OnCollisionExit2D()?

this is on the platform. The debug.log is never even fired when I leave the platform.

function OnCollisionExit2D(col : Collision2D)
{
	Debug.Log("Lost Contact with " + col.gameObject.name);
	
	if (col.gameObject.tag == "Player")
	{
		moveChar = false;
	}
}

For some reason OnTriggerExit2D() Works but not OnCollisionExit2D() so I will stick with trigger.

Ok I cant figure this out I fixed the one area that is an issue now I have a new area. Neither trigger or collision works quite right.

function OnTriggerEnter2D(col : Collider2D)
{
	if (col.tag == "Player")
	{
		Player = col.gameObject;
		movePlayer = true;
	}
}

function OnTriggerExit2D(col : Collider2D)
{
	if (col.tag == "Player")
	{
		movePlayer = false;
	}

}

function OnColiisionExit2D(col : Collision2D)
{
	if (col.gameObject.tag == "Player")
	{
		movePlayer = false;
	}

}

I tried both on my lift platform and it works if you jump off, it works if you walk off onto another platform but if you walk off and fall it doesn’t get called… and movePlayer stays true

You can see in the video the tiny hope when the collision exit isn’t detected. It is still trying to move the player even though the player is no longer on the platform. Anyone have suggestions?

It’s because of local scale. I had to rotate my sprite rather then localScale transform it.

Just wanted to say thanks for posting this, completely fixed a similar issue I was having… I was using localScale.x = -1 to flip my character when changing direction and this seemed to stop the OnCollisionExit2D event firing at certain times. Was going round in circles trying to debug the issue. Thanks!

Hello guys, i am having the same problem and I use localScale to rotate my character as well, but even if a comment the lines that use localScale on my SpinCharacter() function it still don’t work.

Would you please tell me how to solve it ?

Here’s part of the code:

void OnCollisionEnter2D(Collision2D coll) {
** if(coll.collider.name== “Character”){**
** //coll.transform.position = new Vector2(posX,posY);**
** coll.transform.parent = platform.transform; //platform is the gameObject attached to the script**
** }**
** }**
** void OnCollisionExit2D(Collision2D coll) {**
** if(coll.collider.name == “Character”){**
** coll.gameObject.transform.parent = null;**
** } **
** }**

Dude you saved my life thanks for posting this :slight_smile:

Yep, flipping the gameObject (localScale.x = -1) was causing this issue for me too.

Just need to find a different way of flipping my player character :slight_smile:

Thanks