How can I daisy chain two actors together???

Dell7730Dell7730 Member, PRO Posts: 388
edited February 2015 in Community Tutorials

Image Link Here: https://drive.google.com/file/d/0Bw6pFarwlI0eT2RmRWlRZ2hqbkU/view?usp=sharing

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!

Best Answer

  • RThurmanRThurman Posts: 2,879
    Accepted Answer

    I am interested in seeing how you solved this. I bet others would be also. Maybe you can make a demo and share it with the community!

Answers

  • Dell7730Dell7730 Member, PRO Posts: 388

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

  • Dell7730Dell7730 Member, PRO Posts: 388

    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!

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    @dellagarpo -- Great solution! Thanks for sharing.

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

  • Dell7730Dell7730 Member, PRO Posts: 388

    @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.

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

    This was super helpful!

    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)
    Dead (integer)

    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.

    Inside the snake head

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

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

    -Add/Remove row at End
    -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
    -Add/Remove row at End
    -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.

  • PhilipCCPhilipCC Encounter Bay, South AustraliaMember Posts: 1,390

    @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 :star:

Sign In or Register to comment.