- Home /
How to update the Box Collider 2D based on Sprite Size?
Hey, so I have a sprite, and in the idle motion, he goes from needing a 0.26 y for the box collider to needing a 0.27 y. I've tried a couple of solutions like https://answers.unity.com/questions/1204815/how-to-update-2d-colliders-with-spirte-animation.html, but none of them worked for me. How can I do this?
You should be able to modify it the same way you modify the renderer's sprite.
Another solution would be setting the collider's bounds to the renderer's bounds on fixed updates.
Could you give me a code example or website where I could find how to set the collider's bounds to the renderer;s bounds.
void FixedUpdate() {
GetComponent<BoxCollider2D>().bounds = GetComponent<SpriteRenderer>().bounds;
}
Your answer
Follow this Question
Related Questions
SpriteManager 2 1 Answer
How to do you import Spriter animations into Unity? 1 Answer
sprite animation not playings 0 Answers
How to animate a sprite mask? 0 Answers
Sprite animation 2 Answers