I’m working on developing a fairly particular algorithm, but I think the general utility of it to others could come in hand.
I’ve been working on a puzzle mechanic where I have a wheel (like in a gameshow) with four colors. My wheel is mapped out so that one color fits within a face on the wheel. There are four colors so the UV space is as follows in the U direction:
- 0 - 0.25 = color 1
- 0.25 - 0.5 = color 2
- 0.5 - 0.75 = color 3
- 0.75 - 1 = color 4
When the wheel starts spinning, I have a constant rate of speed that I’m applying to the wheel’s UV using Material.SetTextureOffset. When the wheel is asked to stop, I start tweening the speed rate down to 0, so it stops. I’m using iTween and to get a nice end effect, I’m also using easeInOutElastic so that it wobbles to a stop.
The problem I can’t figure out is how to get the UV to land perfectly in a color range (0.25 per color in the U direction). The shortcoming of my approach is that while it looks great, it doesn’t guarantee the precision I need to land completely in a color area. It only controls the speed and the user initiates the stop that starts the speed of the offset of U down to 0.
I’m stumped at the moment for how to solve this. I currently can determine how far off I am from the closest 0.25 increment, so I know if I wanted to click to the nearest color, I could do that.
My question is, how could I use my existing approach, another approach, or some combination of the two, so land perfectly in a 0.25 increment U space and do it gracefully. I really like the elastic effect on the wheel texture stopping and I’m wondering if there’s so place in there to maybe stop it and have another tween take over and go right to it. My worry is there will be a disjoint in the motion.
Thanks for the help.
Update: I’ve uploaded some source files if anyone wants to see what I’m trying to get help with. This shows the panning mechanic and how my existing logic fails to help me pin the stopping point of the tween right on a 0.25 multiple in the UV direction.