Basic top down AI
joshiwu
Member Posts: 207
The only AI. I could find for free was a template @deepblueapps .com , which is fine. But it's not good enough. Would anyone help with an AI that accounts for walls and obstacles.
Ever played desktop tower defense ?? That game is genius. It calculates the fastest route to target. And follows vectored paths towards openings . Anyone got any insight?
Ever played desktop tower defense ?? That game is genius. It calculates the fastest route to target. And follows vectored paths towards openings . Anyone got any insight?
Comments
For that type of AI I think you'll need invisible actors that act as "feelers" to scout ahead of the enemy actor and look for possible collisions. Once a possible collision is registered, the enemy will have to choose a direction and move that way until another possible collision is detected. Another way to do it would be to keep a table of tower positions and then have the enemy calculate a route but I suspect that would be a lot harder to code.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
I get the best results when I use a FSM to control what conditions the actor is responding to.
I give each condition its own rule, and when I know its solid, I will streamline the logic and start using "Otherwise" etc...
It will also help you to isolate the different behaviors from one another. More specifically, find where the behaviors could be improved to closer match what you want.
You could have the walls, or whatever actor record their location to a table, and use those values as coords to avoid.
Gamesalad doesnt have built in "raycasting" so you will have to mock traditional Pathfinding.
Probably the best way, as tatiang mentioned... That will tell your actor what you need to know, but since you mentioned top-down... let me offer one more suggestion, as my opus is also a top-down game.
Use waypoints.
Make an invisible actor, and place it on a "Path" outside the straight line to the target.
record its coords however you want. Trying to explain how to make them obey and follow is pretty hard, since I dont know anything about your game. But start by having them find the nearest waypoint on collision with a wall, and that should give a reasonable idea of what is needed from there.
If you want them to respond before they hit the wall, use another, larger invisible actor, and spawn it on top of your AI and constrain its coords to the AI location.
Set up a rule in this actor so it tracks the coords of the actors who are overlapping or colliding with it and you could use that information to respond to wall before your AI gets there.
Actor with Self.Attributes:
Integer: Self.ID (I usually tie this to the number of AI, and this is mostly for tables)
Integer: Self.State starts as 0
In an FSM, it would be something like this.
When State = 0:
Setup
change Self.ID to Game.ID
change Game.ID to Game.ID+1
Now retrieve location data from where ever you stored it, and setup anything else this actor needs, like Health or whatever. For my example I need a waypoint too. so right now, I will use that, a waypoint actor and the PlayerLocation as my condition to move to the next state.
So when PlayerLocation does not equal 0,0 && Self.Health is equal to (Whatever the health is supposed to be.) && Game.Waypoints does not equal 0
Change State to 1.
When State = 1:
Choose player or waypoint.
Here is where the decision about what to do here will be made. and you can use as much data as you want to determine the condition. But elegance is always nice...
So with that in mind...
You can VectorToAngle Al/Player and AI/Waypoint and use information about their angles relative to each other, and/or
You can use magnitude, to determine distance between AI/Player and AI/Waypoint.
and/or
if you record location data for walls and whatnot, you can check to see if the VectorToAngle of the walls is similar to the VectorToAngle used to reach the player.
say plus or minus some degrees to account for the size of the wall.
If thats true, switch to nearest waypoint,
Change State to 2
if its false, pursue player.
Change State to 3
When State = 2:
Nearest Waypoint
Change Target to Waypoint and go that way...
When AI collides with Waypoint...
Change State to 1
When State = 3:
Pursue Player...
You got a clear shot... interpolate, move, accelerate... however you do it. the time has come. go get 'em.
When Player Health = 0
Change State to 4
When State = 4:
Idle, or Return Home.
I feel so long winded when I post here...
. . . he controls all.
o god, you are right... IT DOES CONTROL EVERYTHING!
mind = blown.
http://forums.gamesalad.com/discussion/comment/384027/#Comment_384027
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User