using { /Verse.org/SceneGraph } using { /Verse.org/SceneGraph/KeyframedMovement } using { /Verse.org/Simulation } using { /Verse.org/SpatialMath } # THE CAPSTONE: a moving platform the player can ride. # # Bolt this onto a platform entity (a floor mesh) that also has a Keyframed # Movement component. Because the mover animates the entity in the pre-physics # phase, a player standing on the surface is carried along — so animating the # floor IS building a rideable elevator. riding_platform_component := class(component): # How high the platform climbs, in units. @editable var RiseHeight:float = 400.0 # How far it slides sideways at the top, in units. @editable var SlideDistance:float = 500.0 # Seconds for each moving leg. @editable var LegSeconds:float = 3.0 # Seconds to pause at each end (a still keyframe = a hold). @editable var HoldSeconds:float = 1.0 OnBeginSimulation():void = (super:)OnBeginSimulation() if (Mover := Entity.GetComponent[keyframed_movement_component]): # Leg 1: rise straight up, gently. Rise := keyframed_movement_delta: Duration := LegSeconds Easing := ease_in_out_cubic_bezier_easing_function{} Transform := transform: Translation := vector3{ Up := RiseHeight, Left := 0.0, Forward := 0.0 } # A hold: zero movement for HoldSeconds, so riders can step on/off. Hold := keyframed_movement_delta: Duration := HoldSeconds Easing := linear_easing_function{} Transform := transform: Translation := vector3{ Up := 0.0, Left := 0.0, Forward := 0.0 } # Leg 2: slide across at the top. Slide := keyframed_movement_delta: Duration := LegSeconds Easing := ease_in_out_cubic_bezier_easing_function{} Transform := transform: Translation := vector3{ Left := SlideDistance, Up := 0.0, Forward := 0.0 } # The full route, read top to bottom: rise, hold, slide, hold. Route := array{ Rise, Hold, Slide, Hold } # Ping-pong replays the route forward then backward forever, so the # platform automatically returns home the way it came. Mover.SetKeyframes(Route, pingpong_keyframed_movement_playback_mode{}) Mover.Play()