Public Group

# Need help working on AI

This topic is 4114 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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 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.

1. 1
2. 2
3. 3
Rutin
19
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631424
• Total Posts
3000008
×