How do I rotate every object in a chain?

  • Preferably without using the For Each loop. Maybe I'm missing an obvious solution so I'm taking a step back here.

    Think of a train with several cars attached to the locomotive. Each car is Pinned to the one before it, and each tries to rotate towards the position of the one it's pinned to for a natural, flowing effect. Now, I was able to do it easily enough using a For Each loop, but, this results in a pretty severe fps drop when there are a lot of cars and trains. Not having a For Each loop in the event apparently makes it not work altogether. So, is there a way to do this without a For Each loop?

    Thanks for any help.

  • If the objects are in index order then just go sprite(self.iid-1).angle.

    Which works for all, but the first indice.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • That... works for the most part! Only issue seems to be having multiple locomotives, which results in the first car of one train turning to face the last car of another one since they're instances of the same object. However, it seems I was able to get around it by assigning custom IDs and Pinning by position & angle in this case.

    Anyway, works lovely now, big thanks!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)