Nudges and Punches (Free Game Polish!)
The term "nudge" refers to pushing a spring to trigger a reaction from it. As we learned earlier, springs don't have a fixed state; we can alter the Current Value or Velocity at any time, and the spring will react and adapt to the change without issues. This ability to nudge the springs gives us the opportunity to add a lot of polish and liveliness to our projects with just a single line of code.
We typically consider two different ways of nudging or punching (we'll use these terms interchangeably):
SetValue: By instantly changing the Current Value using the SetValue method, we can ensure that the Target is different from the Current Value, thereby guaranteeing that an animation will occur. There are some examples of this in the Demo. For instance, in an action game where characters can get hit, we could set the current value of the object's scale on the frame it's hit, causing the object to grow and then animate back to its resting state.
AddVelocity: Similarly, using the AddVelocity method will cause the spring to move. If the spring is at rest with a velocity of 0, it will animate out of the resting state and eventually return to rest. If the velocity was non-zero, it will still influence and nudge the spring in a satisfying way.
Exploring the Demo examples is the best way to see all of these concepts in action and gain a deeper understanding of how nudges and punches can enhance the game juice of your projects.
Last updated