- Home /
Creating a 2D partial ring which expands/contracts in angle and collides
I'm fairly new to Unity and this has me completely stumped.
What I'm looking to make is a ring-shaped "barrier" sprite for my 2D game which rotates around a single point. Over the course of the game, this barrier expands and contracts in angle. At some points, it will be a full 360-degree circle, but the angle of the barrier steadily degrades over time down to around 45 degrees.
In essence, I want to take the behaviour of a radial UI object and apply it to a physics object (check the image below).
The barrier is a main object in a very minimalistic game, therefore the transition in angle needs to look really smooth, as jagged expansion/contraction would end up being really noticeable and jarring.
I've tried to group together lots of small "slices" of ring which overlap each other initially then fan out to make a full 360-degree circle), however the images would always be very slightly misaligned on certain devices and break the effect of a smooth ring.
I've looked into simple masks, but can't figure out how to achieve the desired outcome. I also read about shaders in a slightly related thread but that stuff is way beyond me (but I'll learn more about them if that's the only solution out there).
What's more, it needs to have a 2D collider which accurately readjusts to the barrier's current shape every frame. If the barrier didn't have to constantly change in size, I would usually just make a polygon collider which would auto-fill the shape of the sprite, but now that the shape of the ring is changing every frame, I'm struggling to think of the most performant way to accomplish this.
I would be hugely grateful If anyone can point me in the right direction, even if it's a vague "learn more about X".
Answer by Landern · Dec 14, 2016 at 02:50 PM
@Eric5h5 posted about this a while ago with an example, it uses a gradient mask for the circle and works quite nicely. You can find the UA post here: http://answers.unity3d.com/questions/14770/creating-a-circular-progressbar-timer.html
This is perfect!
Thanks for taking the time to help me out, @Landern :)
Your answer
![](https://koobas.hobune.stream/wayback/20220612102652im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Problem with Vector3 Distance and Mouse Input, 1 Answer
Making the enemy follow the path of the Player,How to make the enemy follow the path of the player? 0 Answers
In my 2D platformer game, how would I create a height marker?, 1 Answer
How to stop crouching automaticaly after getting out of a small area 0 Answers