Download

How can you make a static mesh component grow smoothly when you press a button

Bat and ball game.

When I press a button the bat activates. I want the bat to grow over a period of about 0.5 a second, from tiny to full size.

How would I do this?

The bat is a compent of my main player BP.

Thanks!

Possibly best using a timeline on button press. To do this, right click and “Add Timeline…”, call it GrowTimeline or something, double click it to open it, click the “f+” button to create a float track, change the Length of the timeline to 1.00 seconds, right click on the timeline and Add Key, position this at Time: 0 Value: 0, Add another key and position this at Time: 1, Value: 1.

Now back in your PlayerBP event graph, get your bat mesh, drag off from it and “Set World Scale 3D”. Create a Lerp (Vector) node, in the A Vector input pin, put whatever the scale of the mesh is (i.e. 1.0, 1.0, 1.0) and in the B Vector input pin, put however big you want the mesh to grow to (Since you’re making a bat and ball game, presumably like Breakout, you want the mesh to only scale along 1 axis, so set the B Vector to something like (5.0, 1.0, 1.0) to only scale along the X Axis depending how your mesh is set up). Plug the Alpha pin into the Timeline’s output float pin.

Now, get a Keyboard Event node for whichever Key you want to press to grow the bat. (i.e. Q Key). Right click and “Get GrowTimeline”, drag off from this and Set Play Rate, plug this into Q Key, and set New Rate to a “Float / Float” node, set the top value to 1.0 and the bottom value to 0.5 (Change this to however fast (in seconds) you want the mesh to scale by). Drag off from Get GrowTimeline again and “Play From Start”. Connect this to Set Play Rate.

Note: You don’t need to connect anything into the left execution pins of the Timeline (Play, Play from Start, Reverse etc.) You can call all of these from the GrowTimeline reference.

I answered someone else’s post about a similar question, only they wanted a door to rotate, but the same logic applies to this, just instead of custom events for opening and closing the door, you would use Q Key or whatever key you want, and obviously change the Rotator variables for Vectors and Scale. https://forums.unrealengine.com/deve…t-close-slowly