0 votes

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?

Godot version 3.3.4
in Engine by (15 points)

1 Answer

+1 vote
Best answer

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)
by (7,753 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.