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.
Answer by exzizt · Mar 24, 2018 at 10:30 PM
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.
Your answer
Follow this Question
Related Questions
Moving cubes automatically on the y-axis 0 Answers
It lags when it collides. Help? :( 0 Answers
Why are my wheel colliders making a wheelie? 1 Answer
Pick Up and Drop Script not functioning due to loophole 1 Answer
How do I prevent Circle Collider 2D from rotating when gravity is in effect? 1 Answer