GML Enemy ai?

C

corwin22

Guest
I have been trying to figure out how to make an enemy be able to shoot towards the player and at the same time figure out how to get the bounce (bullets bounce once of walls once before disappearing) the enemies would work similar to the Wii tank game but I have no way of finding out how to get them to shoot the correct direction or get them to move the correct ways (they see player from start).
 
C

corwin22

Guest
i know how to make the bouncing my main issue is getting the enemy to use bouncing to its advantage.
 

Bentley

Member
I have been trying to figure out how to make an enemy be able to shoot towards the player and at the same time figure out how to get the bounce (bullets bounce once of walls once before disappearing) the enemies would work similar to the Wii tank game but I have no way of finding out how to get them to shoot the correct direction or get them to move the correct ways (they see player from start).
Edit: nevermind, answered above.
 
C

corwin22

Guest
i want to try and find out how to have the enemy shoot towards the wall so that it will bounce and hit the player.
 

Bentley

Member
i want to try and find out how to have the enemy shoot towards the wall so that it will bounce and hit the player.
Ah. Hmm. Well, you could "cheat" and actually change the direction of the bullet once it hits the wall. But if you want to plan it out so the trajectory remains after the bounce, than I don't know.
 

NightFrost

Member
I suppose you could do the bounce check with trigonometry. The check is two triangles: hypotenuse of the first is the line from enemy to bounce point at the wall, and hypotenuse of the other is the line from bounce point to player. They share a common side that extends at right angle from the wall at the bounce point. For the triangle that represents the bullet coming from enemy to wall, you must solve the angle of the corner that touches the wall. Then do the same for the other triangle. (You can solve these since you know the lengths of all three sides.) If the angles match, the bullet will bounce to the player from that wall position. You must solve this for every wall pixel the enemy has a line of sight to, in order to find if any of them will bounce directly at the player. There's probably some optimization opportunities there, discarding wall positions that have no chance for a bounce, based on results of nearby calculations.

Edit: added a simple illustration for clarity.

Edit2: actually, looking at the image, it might be better to create the enemy triangle by imagining the enemy position at the same x- or y-coordinate as the player (for vertical and horizontal bounces respectively) and then place the shared side at their halfway point. Then you just check along the shared side both ways for walls, check that there's a line of sight at it from player and enemy, and if all checks pass, you have found a bounce point.
 

Attachments

Last edited:
Top