00:00
00:00
Newgrounds Background Image Theme

Enjoyedthat just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Chain of moving objects - AS3

621 Views | 8 Replies
New Topic Respond to this Topic

Chain of moving objects - AS3 2014-09-21 18:06:15


What I'm trying to make is a dragon with a segmented body in which each segment follows the one before it. The head is obviously going to be the autonomous piece that the others follow. If possible, when one segment is destroyed, I might want to be able to splice a piece out and "shrink" the monster down.

I get that they'll all have to be in the same array with each one behaving in accordance with the segment in front of it. I suppose that I could also handle "rotating" the pieces by checking for movement and for which side the preceding piece is compared to the current. Like, if the preceding piece's x value is greater than the current piece, it will turn into the same direction. I'll figure that in time.

The thing that I don't really get is how to even make a path for all of the segments to follow. Not a straight line path. Say if I want the head to ease up and down slightly as it moves left. How do I make the piece behind the head follow the exact path that the head just traveled on? Would I want to make an ever-updating array of values for x and y positions that the pieces would just move to?

Any ideas are helpful.

Chain of moving objects - AS3

Response to Chain of moving objects - AS3 2014-09-21 19:03:25


At 9/21/14 06:06 PM, Barzona wrote: Any ideas are helpful.

Set each part's movement on a timer, have each part follow the before it, and set each timer for 500ms slower than the last segment (the segment before it)


Programming stuffs (tutorials and extras)

PM me (instead of MintPaw) if you're confuzzled.

thank Skaren for the sig :P

BBS Signature

Response to Chain of moving objects - AS3 2014-09-21 19:06:49


At 9/21/14 07:03 PM, egg82 wrote:
At 9/21/14 06:06 PM, Barzona wrote: Any ideas are helpful.
Set each part's movement on a timer, have each part follow the before it, and set each timer for 500ms slower than the last segment (the segment before it)

Interesting idea. I've got to keep each segment's offset in mind, too. Don't want them to clump together into one spot when it isn't moving.

Response to Chain of moving objects - AS3 2014-09-21 19:12:04


At 9/21/14 06:06 PM, Barzona wrote:

Make the next segment ease to where the current segment currently is, minus an offset so they don't overlap. Like http://www.emanueleferonato.com/2011/10/13/develop-a-flash-game-like-string-avoider-as3-version-and-more/

Response to Chain of moving objects - AS3 2014-09-21 19:37:56


At 9/21/14 07:12 PM, MSGhero wrote:
At 9/21/14 06:06 PM, Barzona wrote:
Make the next segment ease to where the current segment currently is, minus an offset so they don't overlap. Like http://www.emanueleferonato.com/2011/10/13/develop-a-flash-game-like-string-avoider-as3-version-and-more/

I do like that example, but I also want the pieces to move in the same pattern as the head. I don't want them to just drag behind. Now, possibly if the dragon stops curving when it moves, like moves in a straight line, the segments will also stop moving in curves.

Think of it like actual energy is being pushed into the body like real physics.

Chain of moving objects - AS3

Response to Chain of moving objects - AS3 2014-09-21 20:16:40


At 9/21/14 07:37 PM, Barzona wrote: I do like that example, but I also want the pieces to move in the same pattern as the head. I don't want them to just drag behind. Now, possibly if the dragon stops curving when it moves, like moves in a straight line, the segments will also stop moving in curves.

You can keep an array where you add the heads new position in front and remove the last position each time the head moves.
You then use each i's position (0, 5, 10, 15... for example) in this array as position for the segments.

Response to Chain of moving objects - AS3 2014-09-21 21:07:47


You could just set a timer for 100ms or something and after that just tween each piece to the next piece in line using a tween that lasts exactly 100ms.


If ya have something to say, PM me. I have a lot of time to spare.

Also never PM egg82.

BBS Signature

Response to Chain of moving objects - AS3 2014-09-22 13:42:50


At 9/21/14 09:07 PM, MintPaw wrote: You could just set a timer for 100ms or something and after that just tween each piece to the next piece in line using a tween that lasts exactly 100ms.

I could try timers, but I tried just using an offset for array values. You can see how it works here. The head follows the mouse.

Each instance of this class has it's own two arrays for x values and y values. Each array is updated with the x and y positions of the object in front of it in the array. After that, the piece is updated to the new position - 30 of the respective arrays index. That's why all the pieces appear in the top-left before they take their positions (maybe that won't matter depending on how I decide to introduce the enemy at the start of the level).

I should probably also try to make the pieces move to the new coordinates instead of just updating to them for smoother animation..

Response to Chain of moving objects - AS3 2014-09-22 13:56:56


At 9/22/14 01:42 PM, Barzona wrote: I could try timers, but I tried just using an offset for array values. You can see how it works here. The head follows the mouse.

Each instance of this class has it's own two arrays for x values and y values. Each array is updated with the x and y positions of the object in front of it in the array. After that, the piece is updated to the new position - 30 of the respective arrays index. That's why all the pieces appear in the top-left before they take their positions (maybe that won't matter depending on how I decide to introduce the enemy at the start of the level).

I should probably also try to make the pieces move to the new coordinates instead of just updating to them for smoother animation..

Yeah, that's not bad if you want that behaviour, which is much more similar to this


If ya have something to say, PM me. I have a lot of time to spare.

Also never PM egg82.

BBS Signature