Solved: Any Solutions To Passing Collision Data Between Two Actors?
I'm going to use Tower Defence as a good example as to what I'm talking about and the problem I've yet to find a work around for, although I'm not trying to create a Tower Defence game.
If you spawn two or more of the same towers and spawn detection actors for each one how do you get only the one tower to shoot at the enemy when the enemy moves into the circle without relying on game attributes storing the position for every single tower and enemy (although tables is ok)
If the collision rules are on the circles it's not possible to know which of the 10 or so enemy actors has moved on to the circle.
If the collision rules are on the enemies it's not possible to know which of the 2 or 3 copied towers the enemy has passed through.
I saw a video of DeepBlueApps Tower Defense template and thought it had the solution but after buying it I can see that doesn't work as expected when you put more than one of the same gun on the scene because it uses game.attributes instead of table data. And that requires you having game attributes for each tower and requires having seperate actors for each tower (by seperate actors I mean Tower 1, Tower 2, Tower 3, and Tower 4 etc. in your list of prototype actors instead of just one prototype actor called Tower that you can spawn on the scene as many times as you want. You can't really use the template to make a Tower Defence game where the player can add as many towers as they want/can afford.
One thing I was trying to muck about with was have 20 blue actors and 20 red actors on the scene (all spawned from two prototypes: Blue and Red) each with a circle collision detector constrained to them (using table data storing the 40 actors positions with rows added each time one of them is spawned) and when a circle collision detector collides with another actor of a different colour (i.e. the enemy), move that actor towards the enemy actor it collided with. But because it doesn't know which of the 20 actors from the other team it collided with it doesn't know where to move to.
Anyone know of any templates out there where this kind of thing works? I've seen a couple of people in the past working on a Tower Defence game so there must be a solution to it.
Comments
I may not understand exactly what you need to do, and I don't have a tried and tested answer, but would it help to have one actor register it's coordinates on collision and the other react to them. For example when the enemy collides with the tower it sets a global x,y to its' coordinates, and when the tower collides with the enemy it fires at the global x,y?
Why do you need to know which actor moved onto the circle? Assuming the "circle" is the target zone for the tower's bullets, wouldn't the tower just start firing when any actor is overlapping the circle actor? And the enemy actor would have a collision rule for the bullet so it also doesn't need to know which tower fired at it. Or am I missing something?
I realize you're using tower defense as an example so perhaps the difference is that you need it to act differently from a tower defense model. Do you have two "towers" detecting the same circle area? A sketch might make this clearer...
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang and @frd does my example of 20 blue actors spawned from one prototype and 20 red actors spawned from another single prototype actor help explain it. All 40 actors moving around the screen until they detect an enemy (opposite colour) which they then move to. These detections could happen at the same time. I can constrain detection actors to each by updating all of their positions in the table but I don't see how it's possible for anyone of those actors to know which of the other 39 actors it has collided with not without setting up multiple prototypes and multiple game attributes.
The same thing happens in a Tower Defence game. You can buy 10 of the same tower (one Prototype actor) place them all around the screen and you could have an enemy actor move into each of their detection zones at the exact same time and they would all fire independently at the enemy that's moved into their own detection zone. A tower at the bottom right of the screen wouldn't fire at the top left because an enemy at the top has just overwritten the game attribute enemy position.
Tables would be the way to go but then how does the tower at the top know that enemy 12 moved into its detection zone and the bottom right tower knows that enemy 7 moved into its detection zone.
Kind of like this. The top half shows the tower defence action where all the towers are targeting independently and at the same time.
And the bottom half shows actors A and B moving towards each when their detection circles collide.
Sorry the picture is the wrong orientation. Couldn't edit and re-attach
And apologies for the art skills
I get it now!
Let me see if I can make a demo.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
It's not perfect but is this sort of what you're looking for (demo attached)?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Thank you for taking the time to put together a demo @tatiang but unfortunately it's not quite what I was looking for. In your example if you put another instance of the tower actor on the scene it will act the same as the original one and both will move towards the enemy because of the one game attribute enemyIDToTarget, even if the enemy only passed through one of the detection circles. It's not a biggie to be honest, it's more of one of those things that's been jarring me for quite some time and just feel I need to know how to do it even if I don't use it in a project any time soon. Picture your demo with two towers and two enemies, enemy one crossing into tower ones detection circle at the exact same time as enemy two crossing into tower two's detection circle and both targeting or moving towards the enemy that's just moved into their circle.
@jamie_c I remember seeing a post where you was working on a tower defence prototype here: http://forums.gamesalad.com/discussion/91100/tower-defense-game-in-progress, would you be willing to share please (even just a hint/pointer) on how you got each tank reacting by aiming at and shooting the correct enemy that passed through their detection circle and at the same time as other tanks detecting enemies in their zones? All acting independently. I'm assuming that you're spawning multiple copies of one prototype when you're placing the tanks on the scene and haven't got a prototype for each tank you're placing and a haven't got a different set of game attributes for each, unlike the template I've recently bought. If not I would probably be interested in buying a template if you ever release it
I guess I didn't really take it to where you need it to be. It would require syncing the tower circles to each tower (I do that with tables in my enemy health bar demo in the Spare Code thread) and then having enemies and circles check their IDs against each other -- ack! My head is starting to spin. I may take another crack at it but you're probably better off with someone like @jamie_c who has already figured much of this out. =P
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Thank you but don't worry I figured it out and it's so damn simple I'm annoyed with myself lol. It does use a game attribute (but only one). I never imagined it would work as I thought it would get confused with just one.
I've got tables in the attached demo but I don't use them at the moment. And I'm not passing the data from the detection square to the tower yet (I can do that with tables).
What I'm doing is spawning 4 towers and their detection squares (like I said they're not really linked). I then spawn 4 enemies and give each a seperate ID (this is when I would write the towers and enemies to the tables but I'm not in this demo)
I put a rule on the enemies to move after game.Time is greater than 1 second as I want them to all collide with the detection actors at the exact same time. I don't want any fraction of a second delay between each.
When they collide with the detection actor I set their ID into a game attribute called enemyID. On the detection actor I have a rule saying if collides with enemy set a self attribute targetingEnemyID to enemyID and which is displayed at the top of the detection actor.
This is where I thought it would break when they all collide at the same time. With just the one game attribute enemyID I thought they'd all register with the same/last enemyID that was set in the attribute.
All I need to do now is write each tower and enemy to the tables and with that I can target or move to the enemy based on their positions which would be constrained against the correct row in the tables.
Here's a clip of it working
@KevinCross, sounds like you've got what you need working but what I was doing in the post you link to is I had multiple 'detection' zones that pass their data onto one tank actor. This tank actor has behaviors to watch for each different 'detection' zone and act accordingly. So in the end I have multiple detection zones and one tank actor.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page