using { /Verse.org/SceneGraph }
using { /Verse.org/SceneGraph/KeyframedMovement }
using { /Verse.org/Simulation }
using { /Verse.org/SpatialMath }
# Bolt this onto any entity that ALSO has a Keyframed Movement component
# (add one in the editor: Add Component -> Keyframed Movement). When the
# game begins, this glides the entity GlideDistance units forward, smoothly.
glide_to_target_component := class<final_super>(component):
# How far forward to glide, in units. A knob you can tune in the editor.
@editable
var GlideDistance<public>:float = 500.0
# How long the glide should take, in seconds.
@editable
var GlideSeconds<public>:float = 3.0
OnBeginSimulation<override>():void =
# Be polite: let the base class do its own startup first.
(super:)OnBeginSimulation()
# Find the mover sitting on this same entity. Square brackets because
# it can fail — if nobody added a Keyframed Movement component, there's
# nothing to drive, so we just stop.
if (Mover := Entity.GetComponent[keyframed_movement_component]):
# Describe ONE keyframe: "move GlideDistance forward, taking
# GlideSeconds, easing in and out so it starts and stops gently."
# Translation is relative to where the entity is right now.
Step := keyframed_movement_delta:
Verse Library
verse
02 Standalone
Component that smoothly moves an entity forward over a set duration using keyframed easing.
verse-library/verse-anim-move-to-target/02-standalone.verse
Sign in free to read the full source 🌴
This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.