actors spawning on one of three positions, randomized?

ZomparZompar Member, PRO Posts: 6

Hi, I am working on a remake of orc attack (you have to defend a castle by throwing rocks down onto orcs who climb the walls on ladders). my problem: i have three ladders standing on the castle wall and need my orcs to spawn randomly on these three ladders. the positions of the ladders are fixed (ladder 1 at x=150, ladder 2 at x=390, ladder 3 at x= 650)
(i already found a link to a random time spawner here in the forums which will surely help me to spawn the orcs in randomized time intervals. now i need to find a solution for the randomized spwan position). thanks in advance!

Comments

  • ArmellineArmelline Member, PRO Posts: 5,332

    Just use three rules. Either pick a random number in the spawner and spawn in position 1 if random = 1, position 2 if random = 2 etc., or have the actor pick a random number when spawned, move to the position and then become visible.

  • 8bitninja8bitninja Member Posts: 367

    Create a index self attribute in the orc character and call it random_X. Add a change attribute behavior in the orcs actor that reads (Change self-random_X to random 1,3).
    Then create three rules inside of the actor. The first should read (If self-random_X =1) change actors self-position-x to 150. The second should read (If self-random_X =2) change actors self-position-x to 390, and the third should read (If self-random_X =3) change actors self-position-x to 650.

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

    Here is another fun way:

    Change Attribute: orcPosition To: random(1,3)
    Cange Attribute: self.Position.X To: (self.orcPosition==1)and(150)or((self.orcPosition ==2)and(390)or(self.orcPosition==3)and(650))

  • ZomparZompar Member, PRO Posts: 6

    Great, thanks a lot guys for the quick and detailed Replies!!

  • SocksSocks London, UK.Member Posts: 12,822
    edited February 2016

    @RThurman said:
    Here is another fun way:

    Change Attribute: orcPosition To: random(1,3)
    Cange Attribute: self.Position.X To: (self.orcPosition==1)and(150)or((self.orcPosition ==2)and(390)or(self.orcPosition==3)and(650))

    Nice and simple! Here's another simple way:

    Change n to random (0,2)
    Change self.pos.X to 150+(n*240)+((n-(n/n))*20)
    
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    @Zompar -- you are welcome.

    @Socks -- clever!

Sign In or Register to comment.