Be a Supporter!

Zombies and trignometry.

  • 462 Views
  • 21 Replies
New Topic Respond to this Topic
4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
Zombies and trignometry. 2009-02-17 11:48:56 Reply

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.
Forum Stats
Member
Level 46
Blank Slate
Response to Zombies and trignometry. 2009-02-17 12:00:29 Reply

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


- - Flash - Music - Images - -

BBS Signature
Johnny
Johnny
  • Member since: Apr. 17, 2004
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to Zombies and trignometry. 2009-02-17 12:27:46 Reply

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.

BBS Signature
LeechmasterB
LeechmasterB
  • Member since: Apr. 1, 2005
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to Zombies and trignometry. 2009-02-17 12:30:42 Reply

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
Response to Zombies and trignometry. 2009-02-17 12:32:15 Reply

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.
Forum Stats
Member
Level 46
Blank Slate
Response to Zombies and trignometry. 2009-02-17 14:02:38 Reply

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.


- - Flash - Music - Images - -

BBS Signature
Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to Zombies and trignometry. 2009-02-17 14:12:33 Reply

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


- - Flash - Music - Images - -

BBS Signature
Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Zombies and trignometry. 2009-02-17 14:21:25 Reply

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.


BBS Signature
GustTheASGuy
GustTheASGuy
  • Member since: Nov. 2, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Zombies and trignometry. 2009-02-17 14:26:12 Reply

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.


BBS Signature
DJMoran
DJMoran
  • Member since: Mar. 24, 2007
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to Zombies and trignometry. 2009-02-17 15:51:15 Reply

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
Response to Zombies and trignometry. 2009-02-17 16:02:32 Reply

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
Response to Zombies and trignometry. 2009-02-17 16:22:16 Reply

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.

BBS Signature
Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to Zombies and trignometry. 2009-02-17 17:05:38 Reply

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.


- - Flash - Music - Images - -

BBS Signature
Randomini
Randomini
  • Member since: Jul. 7, 2006
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to Zombies and trignometry. 2009-02-17 17:19:14 Reply

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.


BBS Signature
Johnny
Johnny
  • Member since: Apr. 17, 2004
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to Zombies and trignometry. 2009-02-17 17:26:05 Reply

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.

BBS Signature
DefinitiveStar
DefinitiveStar
  • Member since: Aug. 15, 2003
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Zombies and trignometry. 2009-02-17 17:47:04 Reply

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
Response to Zombies and trignometry. 2009-02-17 19:48:24 Reply

At 2/17/09 02:02 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).
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.

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
Response to Zombies and trignometry. 2009-02-19 09:38:28 Reply

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.
Forum Stats
Member
Level 08
Blank Slate
Response to Zombies and trignometry. 2009-02-19 10:30:09 Reply

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.


BBS Signature
Johnny
Johnny
  • Member since: Apr. 17, 2004
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to Zombies and trignometry. 2009-02-19 12:15:11 Reply

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.

BBS Signature
GustTheASGuy
GustTheASGuy
  • Member since: Nov. 2, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Zombies and trignometry. 2009-02-19 13:10:30 Reply

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.


BBS Signature
Johnny
Johnny
  • Member since: Apr. 17, 2004
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to Zombies and trignometry. 2009-02-19 16:19:09 Reply

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. =p
That'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.

BBS Signature