Sign in to follow this  
-pete-

Need help working on AI

Recommended Posts

So I'm working on some really simple AI for a side scrolling shooter. Basically I want the enemies to do a kamikaze style run at the player, I'm a bit of a newb with game development though so I'm having some trouble. Rooting through my old maths book I'm guessing the best way to do it would be to work out a unit vector in the direction of the player and then multiply this by the speed of the unit. To calculate the unit vector I need to: 1. Calculate the vector between the two points 2. Work out the modulus of that vector 3. Find the unit vector by: vector / modulus Am I on the right track here or is there something stupidly simple I've missed?

Share this post


Link to post
Share on other sites
I think your approach would work, go try it! :)

if you fancied cheesing it you can allways move the enemy ship down if it's above the player , or up if it's below.

this is asuming the ships are allways moving to the left (or the players moving to the right..).


the only downside to this is that ships would appear to converge on the hoirzontal vector the player is travelling on, not the player himself.

Share this post


Link to post
Share on other sites
OK so you think that might work? I have another quick question then...


I am going to try and get this working on a DS using PA_lib since its dead easy to mess around with sprites and I want to implement some touch screenyness. However since the DS is... well.... rubbish with floats, is there an easy way to calculate the modulus without using floats or some crazy algorithm?

Share this post


Link to post
Share on other sites
You should see if you can find a library of vector functions for whatever language you are using. It should come with a normalize function for you, among many other useful things you will probably be needing in the future.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this