Flipping Sprite with Box Collider attached

I’m creating a 2D platformer using the sprite flip method when the gameobject changes direction. The player gameobject has a BoxCollider attached.

However, the console is throwing an error saying “BoxColliders does not support negative scale or size.
The effective box size has been forced positive and is likely to give unexpected collision geometry.”

This is now breaking another collision detection script on an enemy gameobject, so I really need to fix this.

The flip code I’m using is:

void Flip(){
		facingRight = !facingRight;
		Vector3 thisScale = transform.localScale;
		thisScale.x *= -1;
		transform.localScale = thisScale;

	}

I know the console suggests a convex Mesh collider instead, but I haven’t really used those when box colliders have been so simple to use in the past.

You could always try flipping your game object’s sprite instead of its entire transform.

GetComponent<SpriteRenderer>().flipX = true;

Or, you could try just creating some constants and using those:

const Vector3 LocalScaleLeft = new Vector3(1f, 1f, 1f);
const Vector3 LocalScaleRight = new Vector3(-1f, 1f, 1f);

Try using something like this instead.