Another platforming obstacle common to the genre is objects that rotate, such as a spinning platform you have to constantly move on, or a bar that moves back and forth that you have to jump over.
The second component of an object’s transform is its rotation, and you can manipulate an object to rotate around an axis. There are several different ways you can use rotation to make unique platforming challenges, and you’ll learn how to code them in this section.
Making Props that Rotate
Follow these steps to build code that rotates your props:
Create a new Verse class named
rotating_propthat inherits frommovable_propusing Verse Explorer. Add the<concrete>specifier to this class to expose its properties to UEFN.Verse# A prop that rotates by an additional rotation or rotates to match # a Creative prop's rotation. rotating_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 } AdditionalRotationTip<localizes>:message = "The rotation to apply to the RootProp." ShouldRotateForeverTip<localizes>:message = "Whether the RootProp should rotate forever." MatchRotationTargetTip<localizes>:message = "The optional prop whose rotation the RootProp should rotate to. Use this if you do not want to set an Additional Rotation." # A prop that rotates by an additional rotation or rotates to matchAt the top of the
rotating_propclass definition, add the following fields.An editable
rotationnamedAdditionalRotation. This is the rotation to apply to the prop. AfterMove()completes, the prop’s rotation will be offset by this value.Verse# The additional rotation to apply to the RootProp. @editable {ToolTip := AdditionalRotationTip} AdditionalRotation:rotation = rotation{}An editable
logicnamedShouldRotateForever. This specifies whether the prop should keep rotating without resetting.Verse# Whether the RootProp should rotate forever. @editable {ToolTip := ShouldRotateForeverTip} ShouldRotateForever:logic = trueAn editable optional
creative_propnamedMatchRotationTarget. If you want your prop to rotate to match another prop’s rotation, you can set this value rather than using theAdditionalRotation.Verse# The optional prop whose rotation RootProp should rotate to match. Use this if you # do not want to set an additional rotation. @editable {ToolTip := MatchRotationTargetTip} MatchRotationTarget:?creative_prop = falseA variable
rotationnamedTargetRotation. This is the rotation the prop is currently rotating toward.Verse# The rotation the prop is currently rotating toward. var TargetRotation:rotation = rotation{}
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 } AdditionalRotationTip<localizes>:message = "The rotation to apply to the RootProp." ShouldRotateForeverTip<localizes>:message = "Whether the RootProp should rotate forever." MatchRotationTargetTip<localizes>:message = "The optional prop whose rotation the RootProp should rotate to. Use this if you do not want to set an Additional Rotation." # A prop that rotates by an additional rotation or rotates to matchSince you already set up the
Move()function that moves your prop inmovable_prop, you can override it in this class. Override theMove()function in yourrotating_propclass. InMove(), first, check if theMatchRotationTargetis set and save it in a variableRotationToMatch. If so, set theTargetRotationto theRotationToMatch. Otherwise, set it to theAdditionalRotation.Verse# Rotate the RootProp by applying the TargetRotation, or toward the MoveTarget if one is set. Move<override>()<suspends>:void= # Set the TargetRotation to the MoveTarget's rotation if the MoveTarget is set. if: RotationToMatch := MatchRotationTarget?.GetTransform().Rotation then: set TargetRotation = RotationToMatch else: set TargetRotation = AdditionalRotationAs with
translating_prop, specify the animation mode for your animation to play. Initialize a newanimation_modevariable namedAnimationModetoanimation_mode.OneShot. This means your animation will stop once your object reaches its target. If the prop should not rotate forever or not move once and stop, set the animation mode to ping pong. Using ping pong will let you make objects that oscillate back and forth, like the bar on a metronome or a bridge that raises and lowers.Verse# Set the default animation mode to play. # The OneShot animation mode will play the animation once. var AnimationMode:animation_mode := animation_mode.OneShot # If the RootProp should not reset and not stop when it finishes rotating, # set the animation mode to PingPong. if: not ShouldRotateForever? and not MoveOnceAndStop? then: set AnimationMode = animation_mode.PingPongIf you set
ShouldResetto false andShouldRotateForeverto true, your prop should keep its position after each animation while continuing to loopMove().Get the rotation for your root prop to rotate toward in a new variable named
RotateByMoveRotationby callingRotateBy()on theStartingTransform, passing theTargetRotation.Then callMoveToEase(). Your completeMove()function should look like this.Verse# Rotate the RootProp by applying the TargetRotation, or toward the MoveTarget if one is set. Move<override>()<suspends>:void= # Set the TargetRotation to the MoveTarget's rotation if the MoveTarget is set. if: RotationToMatch := MatchRotationTarget?.GetTransform().Rotation then: set TargetRotation = RotationToMatch else: set TargetRotation = AdditionalRotationIn your
prop_animatordevice class, add a new editable array ofrotating_propnamedRotatingProps. Add anotherforexpression toOnBegin()that loops through all the rotating 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." # 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 translating props section to create another gap. Add a FG01 Turntable base and a FG01 SpinningBar Double S to your level. Name the base RotatingBase and the bar Spinning Bar. Position the bar above the base, and place both props above the gap.
Setup of the two rotating props. Both the spinning bar and rotating base spin in the same direction at different speeds.
Select your prop animator in the Outliner, and add an array element to RotatingProps for each of your rotating props. Assign each prop with the following values:
| Option | Value | Explanation |
|---|---|---|
Additional Rotation | Z, 90.0 | This prop wsill make a 90-degree rotation around the Z-axis each time. |
RootProp | Assign to prop you’re animating | This is the prop you’re animating. |
Move Duration | 2.0, 3.0 | Assign one of the props a shorter duration so that they rotate at different speeds. |
Move Ease Type | Linear | This will animate your props at a consistent speed. |
Push your changes, then check out your props! Try varying the different values to get different rotations, and try rotating in each of the different dimensions to create different types of obstacles.
Next Up
In the next section, you’ll combine movement and rotation to create props that can do both!
5. Scaling Props
Learn how to manipulate object scales with Verse so they grow and shrink.
Complete Code
Here is the complete code built in this section:
rotating_prop.verse
using { /Fortnite.com/Devices }
using { /Fortnite.com/Devices/CreativeAnimation }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/SpatialMath }
AdditionalRotationTip<localizes>:message = "The rotation to apply to the RootProp."
ShouldRotateForeverTip<localizes>:message = "Whether the RootProp should rotate forever."
MatchRotationTargetTip<localizes>:message = "The optional prop whose rotation the RootProp should rotate to. Use this if you do not want to set an Additional Rotation."
# A prop that rotates by an additional rotation or rotates to match
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."
# Coordinates moving props through animation by calling each prop's Setup() method.
prop_animator := class(creative_device):