Create multiple followpaths from array

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rappa748

Hello!

I browsed a bunch of questions already but I found nothing near what I want. I’m building a race animation and I’m using tween to animate each car, which works fine.

But my next upgrade is to read a json/array with every lap time for each car and animate with those parameters. I looked at Tween and AnimatePlayer already but I couldnt figure out.

Any suggestions on how to approach this?

:bust_in_silhouette: Reply From: Inces

You mean data like this ? :

  var racedata =  {"redcar" : 
 {"lap1" : {"start" : Vector2 "end" Vector2, "time" :float}},
   { "lap2" : {"start" : Vector2 "end" Vector2, "time" :float}}},
{"bluecar" :

I would go for : (in pseudocode)

for CAR in racedata.keys():
       var lapdata = racedata[CAR]
      for LAP in lapdata.keys() :
               var tweendata = lapdata[LAP]
                $Tween.interpolate_property of CAR.position from tweendata["start"] to tweendata["end"] in tweendata["time"] seconds
                Tween.start()
                yield(Tween_finished)

This will animate all cars one after another. If You want to animate all cars simultanoulsy, You just need to make corroutine before iterating all cars in dictionary :

for CAR in racedata.keys():
        animatelaps(racedata[CAR])

func animatelaps(lapdata):
        for LAP in lapdata.keys() :
                   var tweendata = lapdata[LAP]
                    $Tween.interpolate_property of CAR.position from tweendata["start"] to tweendata["end"] in tweendata["time"] seconds
                    Tween.start()
                    yield(Tween_finished)