r/Unity2D • u/AbbreviationsOld6712 • 9d ago
Question/Help How to stop clipping?
I realize this is probably a pretty simple question but I'm new can't find the answer anywhere. My characters keep clipping into each other when turning around. I can't figure out how to add the video of it but this is the code I'm using: transform.localScale = new Vector2(Mathf.Sign(movement2.x), 1);
1
Upvotes
•
u/AutoModerator 9d ago
Reminder: Once your issue has been resolved, please reply !solved to this comment (or comment it anywhere in the thread) and your post's flair will automatically be updated to Solved/Answered. You can also edit it to Solved/Answered yourself.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/QueasyPrior6654 8d ago
Negative scale mirrors the colliders too, around the object's origin. So if your Collider2D has an X offset, it jumps to the other side when you turn and can end up overlapping the other character. A sprite pivot that's off-center horizontally can make the art look like it shifts as well. Do the collider outlines actually overlap, or just the art?
1
u/ShinaDev 8d ago
Sonará tonto pero probaste desmarcar Is Trigger dentro de ambos colliders?
1
u/EthanMerce 7d ago
the scale code itself shouldn't cause characters to physically clip into each other. it's just flipping the transform on the x axis, if you're using colliders, i'd check the collider setup and Rigidbody2D first. make sure the characters aren't using triggers when you actually need physical collision, and check the collision layers/masks too.
also, if you're flipping the whole character object, make sure the collider isn't positioned in a way that changes its effective position when the scale goes from 1 to -1.