#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# How can I daisy chain two actors together???

Posts: 388Member, PRO
edited February 2015

I have a couple of questions for all intelligent minded developers here, and in the illustration, it shows an arrow and it's front and rear side of it, here are several to show what I need done. It's basically a daisy chain problem that's been bothering me for a long time since Gamesalad only have the Collide rule (which I don't really like cause of how it bounces off of each other and each rotates randomly).

1. How can I maintain constant distance between two specific actors, essentially making it not touch and react to its other?

2. And as shown in the picture, how can I make the following actor point its FRONT to the REAR of the followed actor without breaking contact?

Please keep in mind that my brain processing speed is only at 0.3 MPH, LOL!

Any and All help is appreciated! Thanks so much!

• Posts: 388Member, PRO

Already got this! If anyone else needs help on this, let me know!

• Posts: 388Member, PRO

Here's the sample video of it working the way I want it to be: https://youtube.com/watch?v=DzEv9UaSyQw&hd=1

Haven't used any Path like what others have suggested, key to the whole thing is to make each individual actor follow NOT THE LEADER OF THE PACK, but to follow ONLY the actor in FRONT of the following actor. Meaning, you make the very last actor follow the one right in front of it and NOT the actor all the way to the front of the line.

YOU NEED to make 3 Constrain Attributes, One to make the actor FACE the direction of where it's headed and the other two is for the movement towards the X and Y of the actor being followed.

1. Constrain self.rotation to vectorToAngle(self.motion.linearVelocity.x,self.motion.linearVelocity.y)
2. Constrain self.motion.linearVelocity.X to 5*(ACTORTOFOLLOW.position.x-self.position.x)
3. Constrain self.motion.linearVelocity.Y to 5*(ACTORTOFOLLOW.position.y-self.position.y)

I'm very happy with it, hope this helps!

• Posts: 2,818Member, Sous Chef, PRO

@dellagarpo -- Great solution! Thanks for sharing.

And the video looks stunning. You are on to something there!

• Posts: 388Member, PRO

@RThurman said:
dellagarpo -- Great solution! Thanks for sharing.

And the video looks stunning. You are on to something there!

Thanks, can't wait to finish my first project and share to everyone.

• Just a guy, you know. Posts: 236Member, PRO
edited March 2016

I just wanted to say, for anyone else that finds this thread in the future, I used this method to make it so that I could spawn enemies that were chained together.

We need two actors, a snake head, and snake body

Make attribute game.snakerow = 1
Make Table game.snaketable

The snake table has three rows:
X (real)
Y (real)

The reason I used integer on the Dead column is in case you wanted to switch it to 2 or something to indicate to all the different body pieces that they’re invincible or something.

Snake head has two attributes: self.row and self.howmanybodies

Set how many bodies to however many body pieces you want, I chose 5.

-Change game.snakerow to game.snakerow+1
-change self.row to tableRowCount(game.snaketable)
-Timer Every 0 Seconds
Change Table Value
Table: game.snaketable
Row: self.rownumber
Column 1 = self.position.X
Column 2 = self.position.Y
Rule: When self.howmanybodies > 0
Timer Every 0.1 seconds
spawn snake body
Change self.howmanybodies to self.howmanybodies-1
Move however you want the snake to move

-If collide with bullet
-Change Table Value
Table: snake table
Row: Self.row
Column: 3 = 1
-destroy

Inside the snake body

Snake body has one attribute: snakerow

-Change game.snakerow to game.snakerow+1
-change self.row to game.snakerow
-Timer Every 0 seconds
Change Table Value
Table: game.snaketable
Row: self.rownumber
Column 1 = self.position.X
Column 2 = self.position.Y
-Constrain self.rotation to vectorToAngle(self.motion.linear velocity.X, self.motion.linear velocity.X)
-Constrain self.motion.linear velocity.X to 5(game.snaketable, self.row-1,1)-self.position.x)
-Constrain self.motion.linear velocity.Y to 5
(game.snaketable, self.row-1,2)-self.position.y)

If tableCellValue(game.snaketable, self.row-1,3) = 1
(this makes it so that if the body piece ahead of it is destroyed, this one will destroy too)
-Change Table Value
Table: snake table
Row: Self.row
Column: 3 = 1
-destroy

-If collide with bullet
-Change Table Value
Table: snake table
Row: Self.row
Column: 3 = 1
-destroy
(this indicates that the body pieces behind it should also destroy themselves)

Now all you have to do is spawn a snake head whenever you want a whole snake enemy!

I've noticed I can only have a maximum of four 5-bodied snakes before it starts to hit performance, so keep that in mind.

• Encounter Bay, South AustraliaPosts: 1,389Member

@Dell7730 said:
Here's the sample video of it working the way I want it to be: https://youtube.com/watch?v=DzEv9UaSyQw&hd=1

That's a really cool graphic. It moves so fluid and elegantly. I just love the glowing rotation in the "thorax" of the creature, if that's what I can call it. Inspiring work. 5