Could use some help with precision UV Tween algorithm

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.

Source package

Web Build

I solved this problem with a different solution. During the spinning phase where the player is hands off, I use an animation rate like the method detailed in this post UV Scroller - Step Function. When the user interacts and I need to slow the game wheel down, instead of affecting the animationRate to slow the wheel down, I start affecting the uvOffset value directly (see my source or the previous link) in my OnUpdate function. The UpdateUV function doesn’t need to, at this point, apply the animation asset.

The solution is really canned, but the movement is so quick the user is not aware and still the timing of the color that the wheel lands on is the result of skill because I find what color they were in when they stopped the game wheel. I could also do random, but I like to reward players for being quick and dextrous(a la Mario 3 Mushroom Matching Houses).

If anyone has any further questions about this, let me know. I couldn’t find a thing on here about timing animations for UV ranges, so I figure this will help someone eventually.

I’ve posted my source code and working build on my site:

Source package WORKING

Web Build WORKING