How to change a sprite collider at runtime

Hello there!

I am a newcomer to the Unity Editor, and right now building a demo of a side-scrolling shooter game, with pixel art all done using GraphicsGale by HUMANBALANCE Ltd. I’m coming across something that I need to know about before I can try it out in programming.

I have a game object representing the player that holds one sprite renderer, but as the game progresses, depending on how fast the ship goes up and down in space, the sprite changes. What I mean is, at the start, the ship sprite is horizontal. But when the player decides to move up, for example, the program checks both vertical and horizontal speeds and calculates the angle by tangent inverse. I have three states in both directions that approximate to 15°, 30°, and 45°; depending on what the calculated angle is, the sprite is replaced by one that is inclined appropriate to that angle. (I am not directly rotating the game object from the Unity Editor; I’ve tried this on another sprite, and the overall resolution of that sprite when rotated is too high compared to the low pixel res I wanted. I want to retain low pixel quality where in all sprites of the game, there is one size of a pixel that makes them stand out instead sprites consisting of differently-sized pixels, creating a distracting effect.)

As the sprite is changed, the collider has to be changed as well to avoid problems such as player damage from a projectile that has collided with a collider that a section of it is not in the visible sprite.

Anyway, because in the Inspector Pane, I can only hold one sprite renderer at the time, but can hold multiple edge colliders, is there a way I can load one of the edge colliders as the sprite is changed without having to go through recording all the points down and pasting them in the code for instantiation? When I build my game, are all my sliced sprites saved separately, in addition? (I am using edge colliders, because I ran into problems with the polygon collider, where it cannot cover the entire spaceship as one polygon. Instead, there are several polygons together that create empty spaces.)

In full detail, I plan to use seven edge colliders and because of some animations, 224 sprites for my player; 32 for each of the seven angles. (-45, -30, -15, 0, 15, 30, 45, all in degrees)

Please let me know!

Hi GregPDesUGD, I have idea but I didn’t shure is it good solution for your project when you need to change sprite collider when sprite is changed you can delete and add collider component. But when you need do this often is can work in your project very hard

just rotate the renderer through code