- Home /
Power Bar Collision
Hello!
I am trying to create a power/skill bar which when the user taps a button, the bar fills up and when they are not tapping, the bar starts to empty. At the moment I have this working fine. However, I have been asked to see if I can make it so that when the bar reaches a certain point it triggers an event. Again, I have this working but further to that I have been asked to move the point after each trigger. The trigger area is also only a certain size and will be placed randomly along the bar.
Essentially what I am asking is, what would be the best method of creating a power bar that detects when it hits the trigger point? I have attached a sample image of what it looks like for the moment. I tried making it so that the BoxCollider2D I attached would try and follow the furthest point of the bar but this proved to be a lot of hassle. I also tried making is so that the collider was the same size as the image but I couldn't find how anything on to properly scale it.
I assume there may be an easier way than I am trying and I am at a total loss for now! Any help is appreciated.
Thanks.
Answer by TanselAltinel · Apr 29, 2018 at 02:52 PM
Well, instead of trying physics, why not calculate position of the trigger area and how much the bar is filled to see if it is filled up to trigger area. That could be a dynamic algorithm with trigger area boundaries and bar fill rate being inputs and calculation can take place.
I wager it would be easier than trying to collision 2d on UI elements.