Track distance between two AI characters?
ProjectorX
Member Posts: 45
I've got it down with tracking the distance between my main character and my AI's, because I just keep two game attributes "mainCharX" and "mainCharY" constantly updated.
My AI characters are always spawning so there are always many instances of the same actors in the scene.
I obviously can't keep attributes for every one of the hundreds of AI's on the map at one time, so how would I accomplish, for example:
A situation where the "good guy" AI characters are running away from the "bad guy" characters and those "bad guys" are trying to run toward and attack the good guys? Also, the good guys need to be able to run towards tele porters which are spawned by the main char.
But how do I let the AI know where to run to?
I need the ability to do something like this: When (actor with tag: ______ ) is less than ____ px away, execute behaviors.
Thanks for any input on this.
My AI characters are always spawning so there are always many instances of the same actors in the scene.
I obviously can't keep attributes for every one of the hundreds of AI's on the map at one time, so how would I accomplish, for example:
A situation where the "good guy" AI characters are running away from the "bad guy" characters and those "bad guys" are trying to run toward and attack the good guys? Also, the good guys need to be able to run towards tele porters which are spawned by the main char.
But how do I let the AI know where to run to?
I need the ability to do something like this: When (actor with tag: ______ ) is less than ____ px away, execute behaviors.
Thanks for any input on this.
Answers
When self.Distance is less than whatever...
do behaviors here.
Using self.attributes will only apply to the instance that triggers the condition.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
If there were just a way to make game salad account for individual actors' specific attributes only once they were present...
How fast is your gameplay?
You could drop constraints and have them update a table with coords.
Basically attempt to make a finite state machine.
On the AI, make an integer.
Have it start @ zero.
When integer = 0
Do generic behaviors, instead of constrained, move towards nearest waypoint(just a static x&y)
When magnitude < 300
Integer +1
When integer = 1
Make behavior more refined here, with 2 outs. So use an otherwise to set back to 0 if your conditions aren't met. When conditions are met, like magnitude > 300
integer +1
Do even further refined conditions here.
Chase player... Yada yada
Can your main character run around the whole screen? Place teleporters any where on screen?
Is just left to right across the bottom, up and down?
Because I'm tempted to tell you to get REALLY generic.
Instead of setting coords for the AI to travel to, you could just set an angle, and have them move in that direction until other conditions are met.
You could also set up grid system in a table, use booleans to tell if a teleporter is present in that cell location. When a player places a teleporter, have it use the closest cells locations for it.
Unless your actors are tiny, it shouldnt be very noticeable if the distance is only a small amount pixels.
I'll crack open some gamesalad here shortly. Everything I've suggested has been off the top of head, but I can't see any reason why one of these solutions wouldnt fix your issue.
And if there is a maximum number of teleporters (you mentioned 10) code them, place them offscreen. Make rules to move them.
For what you are describing I imagine the performance will be much better than spawning them.
For some reason, I read your project description and imagine Braveheart in space... With William Wallace riding around on horse back yelling FREEDOM! every time he drops a teleporter
@tatiang
You are good source of info, any thoughts on this suggestion?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
FYI: My actors are very small, about 10x10px. They can run around a map filled with obstacles and interactive items (such as houses that bad guys spawn from when close enough) and these maps are mostly at least 1000x1000px It is essentially a multi-directional-shooter where the player can move on both axes and shoot in 360 degrees. (Like Geometry Wars on Xbox). The gameplay is quite fast as it's not a turn-by-turn strategy type game but a shooter. So performance has to be as fast as possible otherwise there will be lag. (Reason global variables and magnitude functions will not work). The actors are tiny but I'm willing to make some sacrifices if I can continue development. This problem has led me to drop development on this game (and gamesalad) completely for over a month and I was pretty excited about it before that!
So I seriously hope I can figure this one out with your guys' help. Thanks!
PS: I've resolved to simply use a larger and invisible "hit area" actor as an alternative to magnitude. The actor would be stuck to the teleporter and good guy actors so that the good guys run to the teles and the bad guys run to the good guys.
In summary: all I need to know is how to get the actors to know where to run. They're already going to know when they're close enough. Thanks again!
performance definitely takes a hit, and it is a lot to program...
I was messing with it GS back whenever we were chatting before, and I don't remember exactly how far I got.
If you want I'll post what I did get accomplished.
But with that said... I have no idea how to help, sorry.