Lerping parented buttons

I am looking to add a ButtonDown state to a script I have and am trying to find the best way to simulate and trigger this effect:

I am trying to work out the best way to get buttons to go down when I click on them, this is something I tried with Lerps but have had little to no success getting the desired effect.

I will most likely need to do this on an axis that I can choose which presents problems in itself as the button may be on the top or sides.

Does anyone know the best way to get this effect?

Bump

What part of Lerp didn’t work? Seems ideal for this.

Keep track of the state of the button: out, moving, in. Change the state to moving when you click, Lerp towards its new position and set the state to in once t = 1.0.

As each button on a panel (like the gif above) has a different position, I need to be able to give a difference, not just move them with a lerp, if I use a lerp all the buttons end up in the same place.

Well you’d obviously only lerp the axis they’re moving on, in this case, Y.

I have tried Lerping like this:

(currentPosition, downPosition.y, Time.deltatime)

But it always fails to compile.

Did you read the documentation on Vector3.Lerp or Mathf.Lerp? Seems like you’re not even trying.

I have found a work around for this (sort of).
Using something like this, I am able to get the current position of the object, and add the difference to it, so calling Lerp on downPos gives us the difference instead of movign the object to 0, 0, 0.1, it adds 0.1 to Z.

downPos = currentPlacement + buttonDown;
        this.transform.localPosition = Vector3.Lerp(currentPlacement, downPos, 0.1f);

The only issue with this method if that I have noticed the button does not smoothly and slowly move, but jumps to the new position.