1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

GML Enemy ai?

Discussion in 'Programming' started by corwin22, Jun 15, 2018.

  1. corwin22

    corwin22 Member

    Joined:
    Nov 18, 2017
    Posts:
    73
    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).
     
  2. Rob

    Rob Member

    Joined:
    Jul 12, 2016
    Posts:
    677
  3. corwin22

    corwin22 Member

    Joined:
    Nov 18, 2017
    Posts:
    73
    i know how to make the bouncing my main issue is getting the enemy to use bouncing to its advantage.
     
  4. Bentley

    Bentley Member

    Joined:
    Jun 18, 2017
    Posts:
    765
    Edit: nevermind, answered above.
     
  5. Bentley

    Bentley Member

    Joined:
    Jun 18, 2017
    Posts:
    765
    What do you mean by that?
     
  6. corwin22

    corwin22 Member

    Joined:
    Nov 18, 2017
    Posts:
    73
    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.
     
  7. Bentley

    Bentley Member

    Joined:
    Jun 18, 2017
    Posts:
    765
    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.
     
    EvanSki likes this.
  8. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    1,871
    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.
     

    Attached Files:

    Last edited: Jun 15, 2018

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice