Some of the easiest obstacles simply move back and forth. You’ll often encounter these in platforming challenges, where you need to time your jumps and make careful moves to avoid falling.
Moving a platform in this way is called translation, or changing the position of an object’s transform. In this section, you’ll learn how to make platforms that not only move back and forth but can move to multiple points in the world, then use these to create your first obstacle!
Making Props That Translate
Follow the steps below to build the code that translates your platforms:
Create a new Verse class named
translating_propthat inherits frommovable_propusing Verse Explorer. Add the<concrete>specifier to this class to expose its properties to UEFN.Verse# A prop that moves (translates) toward either a Creative prop target # or a position in world space. translating_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 } MovePositionTip<localizes>:message = "The optional position to move to World Space. Use this if you do not want to set a MoveTarget." # A prop that moves (translates) toward either a Creative prop target # or a position in world space. translating_prop<public> := class<concrete>(movable_prop):At the top of the
translating_propclass definition, add the following fields:An editable array of
creative_propnamedMoveTargets. These are the Creative props yourRootPropwill move to during gameplay. Using another prop rather than a transform, as the target to move to makes it easier to visualize where your props are headed. You’ll make these invisible during gameplay in the editor later.Verse# The Creative prop targets for the RootProp to move toward. @editable {ToolTip := MoveTargetsTip} var MoveTargets:[]creative_prop = array{}An editable optional
vector3variable namedMovePosition. If you do not assign aMoveTargetprop, your root prop will use this to know where to move to.Verse# The position for the RootProp to move toward. Use this if you # do not want to set a MoveTarget. @editable {ToolTip := MovePositionTip} var MovePosition:?vector3 = falseA variable
vector3namedTargetPosition. This is the position your prop will actually move to and will be set to either the move target’s position or theMovePosition.Verse# The position the prop is currently targeting. var TargetPosition:vector3 = vector3{}Your class definition should look like this:
Verse# A prop that moves (translates) toward either a Creative prop target # or a position in world space. translating_prop<public> := class<concrete>(movable_prop): # The Creative prop targets for the RootProp to move toward. @editable {ToolTip := MoveTargetsTip} var MoveTargets:[]creative_prop = array{} # The optional position for the RootProp to move toward. Use this if you # do not want to set a MoveTarget.
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 yourtranslating_propclass.Verse# Translate toward the MovePosition, or MoveTarget if one is set. Move<override>()<suspends>:void=In
Move(), in anifexpression, check if theMovePositionis set and stored in a valueNewPosition. If so, set theTargetPositionto theNewPosition.Verse# Translate the RootProp toward the MoveTarget, or MovePosition if one is set. Move<override>()<suspends>:void= # Set the TargetPosition to the MovePosition if it is set. if: NewPosition := MovePosition? then: set TargetPosition = NewPositionYour
MoveToEase()function needs ananimation_modeto pass to it. Your animation plays once each timeMove()is called, and theanimation_modecontrols what happens when your animation ends. CallMoveToEase()to pass theTargetPosition, theMoveDuration, theMoveEaseType, andanimation_mode.OneShot. Using this animation mode means your animation will stop once your object reaches its target. This is the overloadedMoveToEase()function you set up earlier that doesn’t take a rotation or scale.Verse# Set the TargetPosition to the MovePosition if it is set. if: NewPosition := MovePosition? then: set TargetPosition = NewPosition # Call MoveToEase to start moving the prop. The OneShot animation mode will play the animation once. RootProp.MoveToEase(TargetPosition, MoveDuration, MoveEaseType, animation_mode.OneShot)While the one-shot animation mode is useful if you want to reset your object or keep it moving, what if you want to play it in reverse? In this case, you can use the
PingPonganimation mode. This will play your animation, then play it in reverse to move the prop back to where it started. There’s also theLoopanimation mode which loops your animation but requires your animation to end in the same place it starts. Pick the right animation mode to suit the needs of your experience.When setting up your props, if you didn’t set a
MovePositionin the editor, you’ll need to set one or moreMoveTargetsfor your root prop to move to. To handle theMoveTargetsin aforexpression, iterate through each target inMoveTargets. Check ifMoveTargetis set by callingIsValid[]. If so, set theTargetPositionto the translation of theMoveTarget.Verse# Set the TargetPosition to the MovePosition if it is set. if: NewPosition := MovePosition? then: set TargetPosition = NewPosition else: for: MoveTarget:MoveTargets do: # Set the TargetPosition to the MoveTarget's position if theFinally, call
MoveToEase(), again withanimation_mode.OneShotas the animation mode. Doing this in aforexpression will move your prop to each of the targets in sequence, resetting at the end or continuing on based on the parameters you set. Your completeMove()function should look like this:Verse# Translate the RootProp toward the MoveTarget, or MovePosition if one is set. Move<override>()<suspends>:void= # Set the TargetPosition to the MovePosition if it is set. if: NewPosition := MovePosition? then: set TargetPosition = NewPosition # Call MoveToEase to start moving the prop. The OneShot animation mode will play the animation once.
Building the Verse Device
Now that your Verse code is complete, you need a way to call it in-level. You’ll use another Verse device to coordinate your props and set up all of them when the game starts. Follow these steps to coordinate your obstacles and move your platforms!
Create a new Verse device named
prop_animatorusing Verse Explorer. This is the device that will coordinate moving your props around.In
prop_animator, add an editable array oftranslating_propnamedTranslatingProps. Then inOnBegin(), in aforexpression, callSetup()on each prop. Your completeprop_animatorfile 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." # Coordinates moving props through animation by calling each moveable_prop's Setup() method. prop_animator := class(creative_device): # Array of moveable_props that translate using animation.Save your code and compile it.
Drag your
prop_animatordevice into the level.
Linking Props to Devices
Back in the editor, delete some of the props near the start to create a gap. Add two FG01 Hover Platform M props to your level. Since these are the platforms you’ll be animating, name them TranslatingPlatform. Then add several FG01 Button Bulb props, which will be the targets each platform will move to. Name these PlatformTarget. Place the platforms over the gap, and make sure to place the targets where you want the platforms to go. You can specify multiple targets for each platform.
Setup of the translating props. Each platform moves back and forth between two move targets as indicated by the arrows.
If you want to hide the target props during gameplay, make sure to set Actor Hidden In Game under Rendering to True for each target.
Drag your prop_animator device into the level, and select it. In the Outliner, add an array element to TranslatingProps for each platform. Assign each prop with the following values:
| Option | Value | Explanation |
|---|---|---|
Move Targets | Assign to the targets you want your prop to move to. | These are the Creative prop targets your prop will move to, in order. |
RootProp | Assign to prop you’re animating. | This is the prop you’re animating. |
Click Launch Session and see your platforms animating! Try varying the MoveDuration, MoveEaseType, and start and end delays to create different scenarios.
Translation is down, and In the next section, you’ll create props that rotate in different directions!
Next Up
Complete Code
Here is the complete code built in this section:
translating_prop.verse
using { /Fortnite.com/Devices }
using { /Fortnite.com/Devices/CreativeAnimation }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/SpatialMath }
MovePositionTip<localizes>:message = "The optional position to move to World Space. Use this if you do not want to set a MoveTarget."
# A prop that moves (translates) toward either a Creative prop target
# or a position in world space.
translating_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."
# Coordinates moving props through animation by calling each moveable_prop's Setup() method.
prop_animator := class(creative_device):
# Array of moveable_props that translate using animation.