How to constrain a spawn actor onto another spawn actor? (FB)

mitdrissiamitdrissia Member Posts: 11
edited March 2014 in Working with GS (Mac)
Hi guys, i am learning gamesalad.
I have 2 questions.
1. How can i constrain a randomly spawn actor on another spawn actor.To visualize, i want a turret to be on top of a pipe like in mario where you see the bottom pipe with a turret that fires bombs.
2. The turret needs to only fire when the player comes near it. How can i achieve this?
thank you

Answers

  • ArmellineArmelline Member, PRO Posts: 5,370
    1. This is very easy to do if there are a limited number of these actors spawning, considerably more difficult to achieve if you want to spawn an unknown number of them.

    If you just have one pipe and one turret spawning at a time, make 2 global attributes. We'll call them... PipeX and PipeY. Inside your pipe prototype, add two constrain attributes - one for PipeX and one for PipeY, constraining the self.position.x and self.position.y of the pipe to them.

    You can then use these value to position and constrain your turret. Something like "Constrain attribute self.position.x to game.pipex" and "Constrain attribute self.position.y to game.pipey+50" or whatever.

    If you want multiple turrets, you can do that too, but it gets... inelegant. I can try to explain how, but don't want to spend all that time typing unless it's what you need to do :D How many turrets are you expecting to spawn at any one time?

    2. There are a few ways to do this. You might want to read up on the magnitude function. You can also constrain the player's X and Y positions to attributes and use rules to work out if it is greater than or less than the turret's position, and within the "range" of the turret.
  • mitdrissiamitdrissia Member Posts: 11
    edited March 2014
    i am using the buzzy bee template. It spawns a complete scene of pipes. I want a turret to appear once in 3 scenes.I think there are around 10 pipes per spawn. I want it to random appear on one of the pipes. I know how to constrain an actor on an actor but not sure how to start doing this when the actors are spawn.
    thanks for the fast reply.
    I forgot to mention that the bottom pipes also move up and down.
  • mitdrissiamitdrissia Member Posts: 11
    I got the constraining part working. I created a spawner (turret)to spawn every 10 sec. The constraining works great but after the 10 sec the turrets comes on each pipe and even he homescreen before playing the game for 10 sec.
    How can i get it to spawn just once in each 10 sec.Also i noticed that when the turret spawns i see it happening.I want the turret to be on the last pipe of the scene so the plane has time to dodge or destroy it with beam.
    I allready came this far, hope someone can help me out.
    thank you
  • mitdrissiamitdrissia Member Posts: 11
    edited March 2014
    Ps For the spawning i used a timer of 10 sec.
    Is this occuring because i have different spawners?
  • ArmellineArmelline Member, PRO Posts: 5,370
    Is your game "endless", or moving from scene to scene? I'm having some trouble picturing exactly what you're doing.
  • mitdrissiamitdrissia Member Posts: 11
    It's endless, like in flappy bird. All actors are spawned.
  • ArmellineArmelline Member, PRO Posts: 5,370
    If you only have one tower spawn at the same time then, just have it spawn at the same location as the tower you want it on, offset to be in the correct place, and have it move using the same method/speed as the tower. You shouldn't need to do any constraining.

    You should be able to use the same spawner and have it only spawn the turret every x spawns of the towers.
  • mitdrissiamitdrissia Member Posts: 11
    edited March 2014
    why i use constrain is because the below pipes move up and down.I need to constrain the turret to stay on top of the pipe. See the pipe as the pipe in mario or flappy bird and see the turret as the bomb spitter that is on one of the pipes.Hope you get the picture. Also i have multiple pipes with random gaps between them.So each time the height of the pipes are not the same.
  • ArmellineArmelline Member, PRO Posts: 5,370
    Do the pipes move up and down in a pre-determined way? If you mirror any movement rules from the pipes into the turret it will move with them.

    As for the random gaps, at some point the gap must be determined. If you spawn your turret between the assigning of that random variable and the generating of the next one, you can still have your turret's initial position correct.
  • mitdrissiamitdrissia Member Posts: 11
    I will try this out. I will let you know tomorrow how it all goes.Hope this will work.thank you for your time and patience
  • mitdrissiamitdrissia Member Posts: 11
    edited March 2014
    This is what i have done.
    I removed the turret spawner and placed it with the other spawner with a timer of 4.5 sec.
    spawn actor turret in front of actor, direction 0 . 0 rel to actor , pos 0 , 0 rel to actor

    In actor "goal" (goal of the game is to get between the pipes) i placed spawn actor turret in front of actor, pos 0 rel to actor, self.position.X, self.gap-210 rel to scene.

    It works much better, the turrets only pass by every 4.5 sec and they move up when the bottom pipes move up. But they are never exactly on top of the bottom pipes.Sometimes its half above the pipe and half of the turret below the pipe, sometimes the turret is way heigher then the bottom pipe.
    Hope we can fix this issue soon
  • mitdrissiamitdrissia Member Posts: 11
    I got it fixed, thanks to mantuapps.

    Also a big thanks Armelline who took the time to help me.
    I appreciate it
Sign In or Register to comment.