Sometimes during platformers, you’ll encounter obstacles that change their dimensions. These could be platforms that grow and shrink in size, or get taller or shorter along a certain axis. When an object’s dimensions are modified this way, it’s called modifying its scale.
An object's scale tells you how much to multiply each of its dimensions, relative to itself. Normally, objects have a scale of {X := 1.0, Y := 1.0, Z := 1.0}. If you double the Z value of an object’s scale, it becomes twice as tall. If you half it, half as tall.
Scale is the final part of the transform puzzle. In this section, you’ll learn how to manipulate scale to create objects that grow and shrink to different sizes.
Making Props that Scale
Follow these steps to build the code that scales your props:
Create a new Verse class named
scaling_propthat inherits frommovable_propusing Verse Explorer. Add the<concrete>specifier to this class to expose its properties to UEFN.Verse# A prop that scales toward either a given scale or a Creative prop's scale. scaling_prop<public> := class<concrete>(movable_prop):Add the
using { /Fortnite.com/Devices/CreativeAnimation }andusing { /UnrealEngine.com/Temporary/SpatialMath }statements to the top of the file to import these modules. You’ll need these to animate your prop. The tooltips used in this section are also included here.Verseusing { /Fortnite.com/Devices } using { /Fortnite.com/Devices/CreativeAnimation } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/SpatialMath } MatchScaleTargetTip<localizes>:message = "The optional position to move to World Space. Use this if you do not want to set a MoveTarget." # A prop that scales toward either a given scale or a Creative prop's scale. scaling_prop<public> := class<concrete>(movable_prop):At the top of the
scaling_propclass definition, add the following fields.An editable
vector3arrayScaleTargets. These are the scales that your prop will grow and shrink to. AfterMove()completes, the prop’s scale will be multiplied by this value.Verse# The array of vector3 targets for the RootProp to scale to. @editable {ToolTip := MoveTargetsTip} var ScaleTargets:[]vector3= array{}An editable optional
creative_propnamedMatchScaleTarget. If you want your prop to scale to match another prop’s scale, you can set this value rather than using theScaleTargets. For example, you could use this if you wanted to create a series of platforms that all grew to the same size before resetting.Verse# The optional Creative prop for the RootProp to match scale to. @editable {ToolTip := MatchScaleTargetTip} var MatchScaleTarget:?creative_prop = falseA variable
rotationnamedTargetScale. This is the scale the prop is currently scaling toward.Verse# The scale the prop is currently targeting. var TargetScale:vector3 = vector3{}
Your final class definition should look like this:
Verseusing { /Fortnite.com/Devices } using { /Fortnite.com/Devices/CreativeAnimation } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/SpatialMath } MatchScaleTargetTip<localizes>:message = "The optional position to move to World Space. Use this if you do not want to set a MoveTarget." # A prop that scales towards either a given scale or a creative prop's scale. scaling_prop<public> := class<concrete>(movable_prop):Since you already set up the
Move()function that moves your prop inmovable_prop, you can override it in this class. Override theMove()function in yourscaling_propclass. InMove(), first, check if theMatchScaleTargetis set and save it in a variableScaleToMatch. If so, set theTargetScaleto theScaleToMatch, then callMoveToEase(), passing in theTargetScale, theMoveDuration, theMoveEaseType, andanimation_mode.OneShot. This is theMoveToEase()function you overloaded earlier that only modifies the scale.Verse# Scale the RootProp toward the ScaleTarget, or MatchScaleTarget if one is set. Move<override>()<suspends>:void= # Set the TargetScale to the MatchScaleTarget if it is set. if: ScaleToMatch := MatchScaleTarget?.GetTransform().Scale then: set TargetScale = ScaleToMatch # Call MoveToEase to start scaling the prop. The OneShot animation mode will play the animation once. RootProp.MoveToEase(MoveDuration, TargetScale, MoveEaseType, animation_mode.OneShot)If you didn’t set a
MatchScaleTarget, then you need to iterate through yourScaleTargetsarray. In aforexpression, iterate through eachScaleTargetinScaleTargetsand set theTargetScaleto theScaleTarget. Then callMoveToEase(), passing the same values as before. Your completeMove()function should look like this:Verse# Scale the RootProp toward the ScaleTarget, or MatchScaleTarget if one is set. Move<override>()<suspends>:void= # Set the TargetScale to the MatchScaleTarget if it is set. if: ScaleToMatch := MatchScaleTarget?.GetTransform().Scale then: set TargetScale = ScaleToMatch # Call MoveToEase to start scaling the prop. The OneShot animation mode will play the animation once.In your
prop_animatordevice class, add a new editable array ofscaling_propnamedScalingProps. Add anotherforexpression toOnBegin()that loops through all the scaling props and callsSetup()on them. Your updatedprop_animatorclass should look like this:Verseusing { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } TranslatingPropsTip<localizes>:message = "The props that translate (move) using animation." RotatingPropsTip<localizes>:message = "The props that rotate using animation." ScalingPropsTip<localizes>:message = "The props that scale using animation." # Coordinates moving props through animation by calling each prop's Setup() method. prop_animator := class(creative_device):Save your code and compile it.
Linking Props to Devices
Back in the editor, delete some of the props after the rotating props section but before the raised blocks to create another gap. Add a FG01 Punch Glove to your level. Name the glove ScalingGlove. Position the glove in the middle of the gap, and rotate it so that it’s facing up.
Setup of the punching glove. The glove scales up to create an elevator to raise players.
Select your prop animator in the Outliner, and add an array element to ScalingProps for your glove. Assign the prop with the following values:
| Option | Value | Explanation |
|---|---|---|
ScaleTargets | {1.0, 2.0, 1.0}, {1.0, 1.0, 1.0} | This prop will scale to twice its dimensions on the Y-axis, then scale back to its starting dimensions. Note that since the prop is rotated, the Y-axis now the local "up" of the prop. |
RootProp | Assign to prop you’re animating. | This is the prop you’re animating. |
Push your changes, then check out your props! Try varying the different scales to get different dimensions, and try scaling other props to create different scenarios!
Next Up
In the next section, you’ll combine movement, rotation, and scale to create props that can do all three!
Complete Code
Here is the complete code built in this section:
scaling_prop.verse
using { /Fortnite.com/Devices }
using { /Fortnite.com/Devices/CreativeAnimation }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/SpatialMath }
MatchScaleTargetTip<localizes>:message = "The optional position to move to World Space. Use this if you do not want to set a MoveTarget."
# A prop that scales towards either a given scale or a creative prop's scale.
scaling_prop<public> := class<concrete>(movable_prop):
prop_animator.verse
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
TranslatingPropsTip<localizes>:message = "The props that translate (move) using animation."
RotatingPropsTip<localizes>:message = "The props that rotate using animation."
ScalingPropsTip<localizes>:message = "The props that scale using animation."
# Coordinates moving props through animation by calling each prop's Setup() method.
prop_animator := class(creative_device):