Zombies and trignometry.
- 4urentertainment
-
4urentertainment
- Member since: Aug. 1, 2008
- Offline.
-
- Forum Stats
- Moderator
- Level 13
- Game Developer
Using my recently learned trigonometry, I was able to do this:
Click here (move with arrow keys)
It's simple, yet effective. I'm trying to do zombie AI. And this would work pretty well, that is, if there were no walls.
So my question is, how do I go about making him see the walls and get past them to the player?
I though about having a big, invisible line going from his face, like twice his length, and if that line hitTests a wall, then the zombie will ignore the player, and seek the closest door/turn then once he's there, get back to chasing the player. But that doesn't sound too practical. Any suggestions?
- Denvish
-
Denvish
- Member since: Apr. 25, 2003
- Offline.
-
- Send Private Message
- Browse All Posts (15,977)
- Block
-
- Forum Stats
- Member
- Level 46
- Blank Slate
At 2/17/09 11:48 AM, 4urentertainment wrote: Using my recently learned trigonometry, I was able to do this:
Click here (move with arrow keys)
It's simple, yet effective. I'm trying to do zombie AI. And this would work pretty well, that is, if there were no walls.
So my question is, how do I go about making him see the walls and get past them to the player?
I though about having a big, invisible line going from his face, like twice his length, and if that line hitTests a wall, then the zombie will ignore the player, and seek the closest door/turn then once he's there, get back to chasing the player. But that doesn't sound too practical. Any suggestions?
Your asking for some pretty complex AI there. You have the right approach though. Run a (probably shapeFlag) hitTest on the wall, calculate the angle between zombie and player (you're already doing that). If this enables the zombie to move up or down the wall (basically you'll need to convert angle back to xvel and yvel) then adjust _x or _y accordingly. Once the hitTest is no longer true, then just move the zombie as normal
- Johnny
-
Johnny
- Member since: Apr. 17, 2004
- Offline.
-
- Forum Stats
- Member
- Level 24
- Blank Slate
AI algorithms, especially pathfinding can be difficult to implement, but you're on the right track.
Just break it down into smaller steps.
Get the zombie's position
Get the player's position
Draw a line from the zombie, to the player.
If there is any interference, the zombie cannot see the player.
Let me elaborate on "Draw a line" though.
This doesn't have to be an actual line.
It just has to be an x/y coordinate... and it only has to be at intervals LESS than the width/height of the objects in the way. If the walls are 20 pixels thick, checking a line of sight ever 19px will work fine. Obviously, it will be on an angle, so you'll have to get the smallest distance overall... or just do an arbitrary check every 5 pixels or so.... then change the zombie's state from canSee = true, to canSee = false if he cannot see the player and include that boolean into a statement.
if(canSee){
//eat his face code
}
Perpetually looking for time to return to the arts.
- LeechmasterB
-
LeechmasterB
- Member since: Apr. 1, 2005
- Offline.
-
- Forum Stats
- Member
- Level 17
- Blank Slate
At 2/17/09 12:00 PM, Denvish wrote: Your asking for some pretty complex AI there. You have the right approach though. Run a (probably shapeFlag) hitTest on the wall, calculate the angle between zombie and player (you're already doing that).
<rant>
You got to be shitting me!
1. That AI is not complex at all!
2. No its exactly the wrong aproach (invisible movieclips and shapeflag hittest? wtf) ever heard about math? It can be done way simpler and less performance intensive.
3. So whenever there is a wall the zombie will ignore the player?
-> FIRST THE PLAYER then THE WALL.
</rant>
- LeechmasterB
-
LeechmasterB
- Member since: Apr. 1, 2005
- Offline.
-
- Forum Stats
- Member
- Level 17
- Blank Slate
At 2/17/09 12:27 PM, Johnny wrote: too much to quote
Yeah thats the way, right on! :)
- Denvish
-
Denvish
- Member since: Apr. 25, 2003
- Offline.
-
- Send Private Message
- Browse All Posts (15,977)
- Block
-
- Forum Stats
- Member
- Level 46
- Blank Slate
At 2/17/09 12:30 PM, LeechmasterB wrote:At 2/17/09 12:00 PM, Denvish wrote: Your asking for some pretty complex AI there. You have the right approach though. Run a (probably shapeFlag) hitTest on the wall, calculate the angle between zombie and player (you're already doing that).
<rant>
You got to be shitting me!
1. That AI is not complex at all!
Yes it is, whatever your theoretical head may think. Any AI is complex coding, particularly to someone who is stumped by this kind of problem.
2. No its exactly the wrong aproach (invisible movieclips and shapeflag hittest? wtf) ever heard about math? It can be done way simpler and less performance intensive.
Approach* I never mentioned invisible MCs, also please explain your reasoning, preferably with code samples. Otherwise I call bullshit.
</rant>
When you can prove yourself by making a living out of coding Flash games, then feel free to diss my advice. Until then, STFU you tit.
- Denvish
-
Denvish
- Member since: Apr. 25, 2003
- Offline.
-
- Send Private Message
- Browse All Posts (15,977)
- Block
-
- Forum Stats
- Member
- Level 46
- Blank Slate
At 2/17/09 12:30 PM, LeechmasterB wrote: 3. So whenever there is a wall the zombie will ignore the player?
PS I did NOT say that
- Toast
-
Toast
- Member since: Apr. 2, 2005
- Offline.
-
- Forum Stats
- Member
- Level 09
- Blank Slate
You can solve it with geometry without doing the line thing. That is, of course, only practical if the obstacles are only simple shapes like squares, rectangles, or even circles. Having a complicated structure will lead to imprecisions. Drawing a line between each zombie and the player, and then checking many points of the lines for hittest with every obstacle in the way may lead to lag.
- GustTheASGuy
-
GustTheASGuy
- Member since: Nov. 2, 2005
- Offline.
-
- Send Private Message
- Browse All Posts (12,016)
- Block
-
- Forum Stats
- Member
- Level 08
- Blank Slate
At 2/17/09 02:02 PM, Denvish wrote: Until then, STFU you tit.
Right on! That fucking tit. :D
Leech: you seem to think you know a lot about programming now, but be sure you have a way to go. Maybe find someone better to talk to.
- DJMoran
-
DJMoran
- Member since: Mar. 24, 2007
- Offline.
-
- Forum Stats
- Member
- Level 12
- Blank Slate
i've seen a very simple A.I. do this (can't remember where) while looking for dynamic path calculation for a TD game
- DJMoran
-
DJMoran
- Member since: Mar. 24, 2007
- Offline.
-
- Forum Stats
- Member
- Level 12
- Blank Slate
At 2/17/09 03:51 PM, DJMoran wrote: i've seen a very simple A.I. do this (can't remember where) while looking for dynamic path calculation for a TD game
No edit button :(
http://www.tonypa.pri.ee/tbw/tut22.html
This is the site with the path finding stuff
- Johnny
-
Johnny
- Member since: Apr. 17, 2004
- Offline.
-
- Forum Stats
- Member
- Level 24
- Blank Slate
I think Leech might have some kind of rage complex. Why yell at granpa Denvish? Den could say the sky was green, and instead of yelling at him, we would just call him an old coot and laugh it up with a pipe and rocking chair.
Be nice to him.
Besides, he's one of the most respected and knowledgeable members of our little community, enough so to realize that sometimes the best answer to a problem is a solution the person will understand... even if it isn't necessarily the most efficient.
Perpetually looking for time to return to the arts.
- Denvish
-
Denvish
- Member since: Apr. 25, 2003
- Offline.
-
- Send Private Message
- Browse All Posts (15,977)
- Block
-
- Forum Stats
- Member
- Level 46
- Blank Slate
At 2/17/09 12:27 PM, Johnny wrote: AI algorithms, especially pathfinding can be difficult to implement, but you're on the right track.
It just has to be an x/y coordinate... and it only has to be at intervals LESS than the width/height of the objects in the way. If the walls are 20 pixels thick, checking a line of sight ever 19px will work fine. Obviously, it will be on an angle, so you'll have to get the smallest distance overall... or just do an arbitrary check every 5 pixels or so.... then change the zombie's state from canSee = true, to canSee = false if he cannot see the player and include that boolean into a statement.
if(canSee){
//eat his face code
}
Appreciate you supporting my aged status, but the topic starter still wants the zombie to seek the nearest door when !canSee. That's the complex bit - which, as I said, is why even apparently simple AI is NOT simple. I admit, my solution would end up with zombies stuck in room corners, but the only other solution is to use tile-based or rotation-based/shapeflag hitTest pathfinding (ps in this scenario I'd go for the later as more efficient/easier to implement), which is a whole new ball game.
- Randomini
-
Randomini
- Member since: Jul. 7, 2006
- Offline.
-
- Forum Stats
- Member
- Level 13
- Blank Slate
In each room, your character should generate a different global variable. If the zombie in the room doesn't share that variable, find the door that leads to that room.
- Johnny
-
Johnny
- Member since: Apr. 17, 2004
- Offline.
-
- Forum Stats
- Member
- Level 24
- Blank Slate
At 2/17/09 05:05 PM, Denvish wrote: Appreciate you supporting my aged status, but the topic starter still wants the zombie to seek the nearest door when !canSee.
Yeah... I didn't read the entire post. Guess I'll get on that.
Perpetually looking for time to return to the arts.
- DefinitiveStar
-
DefinitiveStar
- Member since: Aug. 15, 2003
- Offline.
-
- Forum Stats
- Member
- Level 03
- Blank Slate
At 2/17/09 05:26 PM, Johnny wrote:At 2/17/09 05:05 PM, Denvish wrote: Appreciate you supporting my aged status, but the topic starter still wants the zombie to seek the nearest door when !canSee.Yeah... I didn't read the entire post. Guess I'll get on that.
You do that funkeh thang :D
- LeechmasterB
-
LeechmasterB
- Member since: Apr. 1, 2005
- Offline.
-
- Forum Stats
- Member
- Level 17
- Blank Slate
At 2/17/09 02:02 PM, Denvish wrote:Yes it is, whatever your theoretical head may think. Any AI is complex coding, particularly to someone who is stumped by this kind of problem.Your asking for some pretty complex AI there. You have the right approach though. Run a (probably shapeFlag) hitTest on the wall, calculate the angle between zombie and player (you're already doing that).
That type of AI really is not. Complex AI is something entirely different, anyone can do hittests. What about learning AI, neural networks and genetic algorithms. Multi layered AI, Pathfinding (djikstra, AStar..) and whatever more there is... thats all beyond a stupid movieclip doing hittests.
Approach* I never mentioned invisible MCs, also please explain your reasoning, preferably with code samples. Otherwise I call bullshit.
I call the word "shapeflag" and "hittest" bullshit.
When you can prove yourself by making a living out of coding Flash games, then feel free to diss my advice. Until then, STFU you tit.
Why would i want to make a living out of flash games? Just because you earn money with it does not mean that you are a good programmer. And in my opinion there would not be so many noob questions every day if people told em how to do it right instead of pointing to bad tutorials and giving bad coding advice. There is simply too much crap that missguides out there.
At 2/17/09 02:26 PM, GustTheASGuy wrote: Leech: you seem to think you know a lot about programming now, but be sure you have a way to go. Maybe find someone better to talk to.
I am just stating my opinion on bad coding and trying to help every now and then. Do you think you know a lot about programming? Why would it concern you what i think?
- 4urentertainment
-
4urentertainment
- Member since: Aug. 1, 2008
- Offline.
-
- Forum Stats
- Moderator
- Level 13
- Game Developer
Don't you just hate it when an innocent little question turns into a flame war?
Anyway, I have been trying to use simple methods to work out all my problems in my first engine: link
And as you may have probably noticed, I'm not so good as to use OOP (using tiles is OOP right?)
So my question is, should I move on and try to understand this tutorial without copying or is there an easier way?
P.S:
Controls:
Move with WASD
Run with Shift
fire with mouse
change weapons with Q,E
reload with R
switch light off with F
kick with SPACE
- GustTheASGuy
-
GustTheASGuy
- Member since: Nov. 2, 2005
- Offline.
-
- Send Private Message
- Browse All Posts (12,016)
- Block
-
- Forum Stats
- Member
- Level 08
- Blank Slate
At 2/19/09 09:38 AM, 4urentertainment wrote: And as you may have probably noticed, I'm not so good as to use OOP (using tiles is OOP right?)
Haha, no.
So my question is, should I move on and try to understand this tutorial without copying or is there an easier way?
Johnny described the most appropriate way for you. Problem? Blind?
As for the question - no, you'll get nowhere.
- Johnny
-
Johnny
- Member since: Apr. 17, 2004
- Offline.
-
- Forum Stats
- Member
- Level 24
- Blank Slate
At 2/19/09 10:30 AM, GustTheASGuy wrote:At 2/19/09 09:38 AM, 4urentertainment wrote: And as you may have probably noticed, I'm not so good as to use OOP (using tiles is OOP right?)Haha, no.
Could be, if each tile were an Object and everything was stored in classes. =p
Perpetually looking for time to return to the arts.
- GustTheASGuy
-
GustTheASGuy
- Member since: Nov. 2, 2005
- Offline.
-
- Send Private Message
- Browse All Posts (12,016)
- Block
-
- Forum Stats
- Member
- Level 08
- Blank Slate
At 2/19/09 12:15 PM, Johnny wrote: Could be, if each tile were an Object and everything was stored in classes. =p
That's irrelevant. How geometry is handled has nothing to do with OOP.
- Johnny
-
Johnny
- Member since: Apr. 17, 2004
- Offline.
-
- Forum Stats
- Member
- Level 24
- Blank Slate
At 2/19/09 01:10 PM, GustTheASGuy wrote:At 2/19/09 12:15 PM, Johnny wrote: Could be, if each tile were an Object and everything was stored in classes. =pThat's irrelevant. How geometry is handled has nothing to do with OOP.
My comment was just in reference to the "Tiles are OOP, right?" Summing up with saying any type of game can be OOP, depending on the setup of the individual objects is all.
Perpetually looking for time to return to the arts.



