Tracking like in Zelda
Hi,
i am writing a game like Zelda and the Monsters there only follow you. Do u know where i can get some examples or Informations for Tracking?
Something better than this:
if ( player_x > monster_x )
{
monster_x += 4;
monster_dx = 4;
}
else
if ( player_x < monster_x )
{
monster_x -= 4;
monster_dx = -4;
cMonster::Animation( MONSTER_WALK_LEFT );
}
else
if ( player_x > monster_y )
{
monster_y += 4;
}
else
if ( player_y < monster_y )
{
monster_y -= 4;
}
}
Thanx
Lutz Hören
psYchOtroW
Well, I remember in the old AI Competition for MZX there were some well-written tracking algorithims. Most of them worked with more than one player, but I suppose that''s not an issue. Still, in situations like this, I prefer to have the monsters/whatever not be able to access data that would be illogical to access; Rather than having them check the player''s position, have a quick little routine that checks the surrounding map for a player, and then seeks towards her. A basic but functional and rather effective algorithim is to have the monster wander around when it can''t see the player; pick a direction and a random number n, and have it continue in the direction until it hits a wall or walks n spaces, and then pick a different direction (that isn''t the direction it came in and isn''t blocked by a wall.)
Then when it''s within 5 spaces or so of the player [or more, depending on the size of your map spaces), and there''s no blocks between it and the player, have it aim towards the player.
+------------------------------------------------
| Thp :: Threep2742@worldnet.att.net
| "Nature uses only the longest threads to
| weave her patterns, so each small piece
| of her fabric reveals the organization of
| the entire tapestry." -- Richard P. Feynman
Then when it''s within 5 spaces or so of the player [or more, depending on the size of your map spaces), and there''s no blocks between it and the player, have it aim towards the player.
+------------------------------------------------
| Thp :: Threep2742@worldnet.att.net
| "Nature uses only the longest threads to
| weave her patterns, so each small piece
| of her fabric reveals the organization of
| the entire tapestry." -- Richard P. Feynman
+------------------------------------------------| Thp :: Threep2742@worldnet.att.net| "Nature uses only the longest threads to| weave her patterns, so each small piece| of her fabric reveals the organization of| the entire tapestry." -- Richard P. Feynman
November 10, 2000 04:47 AM
you could also put markers on the spots where the creature
has already been, have the marker degrade over time, and steer the creature in the direction of the smallest marker, until it sees the player.
has already been, have the marker degrade over time, and steer the creature in the direction of the smallest marker, until it sees the player.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement