using { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/SpatialMath } # This is our custom device. Think of it as a new type of device you're inventing. PathFollower := class(creative_device): # @editable means these fields show up in the UEFN Details panel. # You can drag and drop items here in the editor. # The object we want to move (e.g., a boat, a platform) PropToMove: creative_prop := creative_prop{} # How fast it moves (in Unreal Units per second) Speed: float := 500.0 # The list of waypoints (flags, cubes, etc.) that define the path Waypoints: []creative_prop := array{} # Internal variables (not visible in editor, used for logic) var current_index: int = 0 var is_moving: bool = false # OnBegin runs once when the island starts. OnBegin(): void = # Check if we actually have a prop and waypoints assigned if PropToMove != creative_prop{} and len(Waypoints) > 0: # Start the movement loop _StartMoving() # A helper function to handle the actual movement loop _StartMoving(): void = loop: # Get the target location from the current waypoint in our list target_prop := Waypoints[current_index] # If the waypoint exists, get its location if target_prop != creative_prop{}: target_location := target_prop.GetTransform().Location # Calculate direction and distance direction := target_location - PropToMove.GetTransform().Location distance := len(direction) # If we are close enough to the target (within 10 units), move to next if distance < 10.0: # Move to the next waypoint current_index = (current_index + 1) % len(Waypoints) # Wait a tiny bit to prevent instant jumping Wait(0.1) else: # Move towards the target # Normalize direction (make it length 1) then multiply by speed move_step := (direction / distance) * Speed * 0.016 # 0.016 is approx 1/60th of a second PropToMove.SetLocation(PropToMove.GetTransform().Location + move_step) # Pause for one frame (approx 16ms) Wait(0.016)