Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Platform enemy AI

Author
Message
Camronas
16
Years of Service
User Offline
Joined: 2nd Jul 2010
Location:
Posted: 10th Jul 2010 05:12
Im trying to make a platofrmer with enemies that will follow the play (and attack him/her) but im finding it really hard at the moment.

Im thinking of having a function that checks if the player is with im x, y of the enemy, if so the enemy follows them. Should I know I need an array to monitor the enemies but not to sure how to get the data from the array to make them move.
Zotoaster
21
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 10th Jul 2010 18:13
I wrote a tutorial on some very basic AI a long time ago. It's in the Tutorials Thread in Newcomers Corner. It's not for platformers but it will teach you how to maintain your enemies using arrays and control them based on the position of the player.

"everyone forgets a semi-colon sometimes." - Phaelax
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 10th Jul 2010 19:07
I made a platform game (Bruce) which was a tutorial feature in the newsletter, maybe worth checking that to see if it's the sort of thing your looking for. I'm not saying it's ideal for newcommers, but the basic principles of the AI is really quite straightforward.

I found it easiest to make the enemy controllable as a player, so each enemy gets the same sort of properties as your player, animation system, movement, jumping etc. Get this working right, and adding AI is a lot neater and easier. I used the same function to control and update the player, and update the AI characters, just hijacked the controls depending on what the player is doing.
Each loop I would check the distance between the player and the character, work out which side the player is on, and if the player is above or below. Then if say, the AI character is static, then they might just run towards the player if they are on the same height, if they are already running, they will turn around to run towards the player. If the character gets to the edge of a platform, then they could try to jump across, depending on a collision check to make sure there's something to land on - maybe if the player is on the same height they try to jump, if the player is below they can drop down. Climbing ladders and jumping are the most complex. For ladders I checked if the player is above or below, and the character is standing at a ladder, they climb up or down.

I used a typed array, and stored the mode, like run left, run right, climb up - then it's easy to add logic, like if climbing then check to make sure there's still ladder, and when there's no ladder left, go to a static pose - then the next loop, if the character is static, head towards the player again.

For attacking, I just checked the distance, and set the mode to attack if it's a good aim - usually best to work it out when your attack animations are in place, it depends really on how they attack. More complex attacking might require better collision. My characters are 3D models with bone structures, so I used line collision, with kung fu moves, like punches - I track the fist and arm with the whole bone structure of the enemies, so it gives quite decen attack detection.


Health, Ammo, and bacon and eggs!
Camronas
16
Years of Service
User Offline
Joined: 2nd Jul 2010
Location:
Posted: 12th Jul 2010 05:15
Ah nice! thanks for the help its working alot better know thanks.

Login to post a reply

Server time is: 2026-07-25 08:13:10
Your offset time is: 2026-07-25 08:13:10