My first MoveTo script in loop! Can you help me to make it better?

Hello guys, I created my first MoveTo script in loop. However, it requires refactoring IMO.

This Verse Script controlling 1 Truck. There is a FirstTruckPosition and TargetTruckPosition, When Truck arrived to TargetTruckPosition, I teleport it back to FirstTruckPosition.

I have to create 3 editable for that script. Is there any way to make this code better and readable?

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.

# A Verse-authored creative device that can be placed in a level
traffic_manager := class(creative_device):

    @editable
    var Truck : creative_prop = creative_prop{}
    
    @editable
    var Truck1FirstPos : creative_prop = creative_prop{}
    @editable
    var Truck1LastPos : creative_prop = creative_prop{}
    
    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        SmoothMovement(Truck,Truck1FirstPos,Truck1LastPos,25.0)
        
    SmoothMovement<private>(Prop : creative_prop, FirstPosition : creative_prop, Target : creative_prop, Speed : float)<suspends> : void=

        Transform := Prop.GetTransform()
        Position := Transform.Translation
        Rotation := Transform.Rotation
        TargetTransform := Target.GetTransform()
        NewPosition := TargetTransform.Translation
        **MoveResult := Prop.MoveTo(NewPosition, Rotation, Speed)**
**        # It suspends here**
**        if (MoveResult = move_to_result.DestinationReached):    **
**            PropTeleport(Prop,FirstPosition)**
**            SmoothMovement(Prop, FirstPosition,Target, Speed)**
            

    PropTeleport(Prop: creative_prop, FirstPosition: creative_prop)<suspends>:void=
            Transform := Prop.GetTransform()
            Position := Transform.Translation
            Rotation := Transform.Rotation

            FirstTransform := FirstPosition.GetTransform()
            FirstPos := FirstTransform.Translation
            FirstRot := FirstTransform.Rotation
            if(Prop.TeleportTo[FirstPos,FirstRot]){}

1 Like

I need help with this