Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 03-28-2012, 02:14 PM   #1
jm_taylor
Registered User
 
Join Date: Feb 2012
Posts: 20
Default [AS3] rpg style game - enemies chasing player

Hey, I'm making a top down rpg style game and I'm looking for a reeeeeally simple way of getting my enemies to follow the player if they're nearby.

I have the enemies pushed into an array from the start.

I'm looking for something dead simple.

Let me know if you want to see specific parts of my code as there's over 1000 lines at the moment.

Any help would be greatly appreciated. I've been struggling with this for a few weeks now.

Joe
jm_taylor is offline   Reply With Quote
Old 03-28-2012, 02:48 PM   #2
abeall
Senior Member
 
Join Date: Feb 2006
Location: Washington, DC
Posts: 2,796
Send a message via AIM to abeall
Default

Making some assumptions as to how you want your enemies to move, the simplest approach would probably be:

1. Every frame, loop through the array, and for each enemy...

2. Determine distance between player and enemy using Point.distance or the distance formula

3. If within desired chase distance, point the enemy towards the player using the angle between two points formula

4. Move the enemy towards the player using basic vector movement

Working in "rotate towards" behavior and enemy movement acceleration would not be too hard either, check google.
__________________
Aaron Beall | Flash portfolio | Fireworks extensions | Twitter
abeall is offline   Reply With Quote
Old 03-28-2012, 05:35 PM   #3
jm_taylor
Registered User
 
Join Date: Feb 2012
Posts: 20
Default

Thanks for that, I got this to work perfectly now!
jm_taylor is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:31 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.