Now that you’ve created entities that move back and forth between targets, it’s time to build a prefab you can use to quickly set up your own level.
Creating the Prefab
To start, you’ll need to define the set of entities that make up your moving entity. Each set will have multiple entities. The first entity will represent the platform itself, while other entities will represent the destinations the platform will move to. Follow these steps to create your resetting platform prefab:
Add an entity to your scene named
AnimatingBlockSet. For how to add entities and components to your scene, see Working with Entities and Components.Add another entity named
AnimatingBlockto your scene as a child of theAnimatingBlockSet. Set this entity’s transform to the parent’s transform. This is the entity that will animate.Add a
mesh_componentto your AnimatingBlock and assign it the cube.Add an
animate_to_targets_componentand akeyframed_movement_componentto theAnimatingBlock. This is the Verse component you defined earlier.Add three new entities to the scene named
StartingTarget,Target2, andTarget3, and set them as children of theAnimatingBlockSet. Add themesh_componentto each of them and set it to sphere. This will allow you to visualize where your entity is moving in the world.You can reposition these entities to move the platform to different areas, and you can disable their
mesh_componentonce you have your block positioned to prevent the sphere from showing up during gameplay.Position
StartingTargetat the same transform asAnimatingBlock, andTarget2andTarget3in places where you want the block to move. Try givingTarget2andTarget3different scales and rotations so you can see how the block changes as it animates to each of them.Select the
AnimatingBlockentity in the editor. In the Details panel, add three items to theSegmentsarray. Set theSegmentStartPositionto each target entity in the order you want the block to travel to them. You can also change thePauseSeconds,AnimationDuration, andEasingFunctionto customize the block’s movement.Finally, right-click on your
AnimatingEntitySetin the Outliner and select Save As Prefab. Name this prefabanimating_entity_prefab.
Example prefab using the setup from earlier. Since Target2 and Target3 have different scales and rotations, the AnimatingBlock will scale and rotate appropriately as it travels to them.
Building a Platforming Level
And that’s it! Now that you’ve finished all the groundwork, it’s time to get building! You’ll use the prefabs you’ve created to quickly build a platforming level!
At the start of your level, try using the animating_entity_set_prefab to create a bridge structure that builds itself. You can override the mesh_component on each entity with your own custom meshes to add some style. Use the oneshot animation mode to make sure the blocks stay in place when they finish moving.
Blocks slowly animate into place to build a bridge for the player to cross.
Next, place a few of the animating_entity_set_prefab you’ve built to create a series of platforms players have to carefully navigate across. Try varying the AnimationDuration, PauseSeconds, and EasingFunction on each segment to make each platform unique, and keep players on their toes. In the following setup, the player has to cross three platforms, each with different animation durations and pause times.
Jumps become a lot more intense when they’re over lava.
Because all your entities will start simulating around the exact same time, your platforms will also all start moving at the same time. Keep this in mind while placing your platforms, especially if you have multiple platforms moving in the same direction, as this may make some jumps impossible unless you vary their AnimationDuration and PauseSeconds.
What about platforms that disappear on a loop? Using the disappearing_entity_prefab, create a section where players have to jump over platforms that disappear and reappear at different times. Vary the Duration of these to create tricky situations for your players.
Players need to pay careful attention to the timing of each entity to cross this section.
Finally, try using the animating_entity_prefab as an obstacle players have to avoid. In the following setup, the player has to cross a series of platforms across a pond while being chased by a giant block. The block has different animation durations and pause times to make crossing the pond hectic, but not impossible.
It isn’t easy to relax by the pond when you’re being chased by a giant cube.
On Your Own
And that’s it! By completing this guide you’ve learned how to use custom Verse components to create your own platformer. Using what you’ve learned, try to do the following:
Can you use multiple Verse components on the same platform to create interesting scenarios? How about a platform that moves and disappears at the same time?
Think about what other kinds of components you could use for a platformer. How about a platform that uses the light component to signal when you can step on it or a particle system component that tells you if the platform might damage you?
Try creating other custom Verse components to create new types of obstacles. What about an entity you can only pass through when it’s the right color? What about a homing entity that detects where a player is and slowly follows them?
Complete Code
Here is the complete code built in this tutorial:
disappear_on_loop_component.verse
using { /Verse.org }
using { /Verse.org/Native }
using { /Verse.org/Simulation }
using { /Verse.org/SceneGraph }
# Loops between hiding and showing the entity by enabling and disabling
# its static mesh and collision components.
disappear_on_loop_component := class<final_super>(component):
animate_to_targets_component.verse
using { /Verse.org }
using { /Verse.org/Native }
using { /Verse.org/Random }
using { /Verse.org/Simulation }
using { /Verse.org/SpatialMath }
using { /Verse.org/SceneGraph }
using { /Verse.org/SceneGraph/KeyframedMovement }
using { /UnrealEngine.com }
# Editor Tool Tips