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(component): # How far forward to glide, in units. A knob you can tune in the editor. @editable var GlideDistance:float = 500.0 # How long the glide should take, in seconds. @editable var GlideSeconds:float = 3.0 OnBeginSimulation():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: Duration := GlideSeconds Easing := ease_in_out_cubic_bezier_easing_function{} Transform := transform: Translation := vector3: Forward := GlideDistance Left := 0.0 Up := 0.0 # Hand the keyframe list to the mover and tell it to play once. Mover.SetKeyframes(array{Step}, oneshot_keyframed_movement_playback_mode{}) Mover.Play()