1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

How do i make an AI Enemy shoot at the player?

Discussion in 'Programming' started by Player12Coconut, Jan 16, 2018.

  1. Bentley

    Bentley Member

    Joined:
    Jun 18, 2017
    Posts:
    823
    I believe that when it reads this line:
    Code:
    point_direction(x, y, WinterShipFighter.x, WinterShipFighter.y) 
    The instance doesn't exist yet. In other words, it's checking for an instance that is not in the room, and therefore gives you an error. It's also possible that you don't have an object named that (but I don't think that's what's going on in your case).

    I highly recommend prefixing your resources. obj_WinterShipFighter is the way to go. Do the same for your sprites.
     
    Player12Coconut likes this.
  2. but i already changed it to obj_WinterShipFighter
    and changed all of the codes that are WinterShipFighter to obj_WinterShipFighter
     
  3. Bentley

    Bentley Member

    Joined:
    Jun 18, 2017
    Posts:
    823
    Then that is why you're getting that error. The code is checking for "WinterShipFighter" which doesn't exist. Make it check for "obj_WinterShipFighter". Switch the names in that line of code.
     
  4. But I already did. It’s also highlighted as an Object. The code in that line is
    direction = point_direction(x, y, obj_WinterShipFighter.x, obj_WinterShipFighter.y);
     
    Last edited by a moderator: Jan 21, 2018
  5. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,148
    Go to the alarm 0 event in empiregunners. Fix your code. The error says you missed that part.

    Then click the dustpan icon to clear the project cache.
     
    Player12Coconut likes this.
  6. It also happens when WinterShipFighter hits something else that has a collusion with it and in it has the code instance destroy. I don't think it has anything to do with the Empire gunners or the lasers. The error happened whenever the WinterShipFighter goes over Destroy Instance.
     
  7. What do you mean by "Fix your code"?
     
  8. I found out what was the problem. I made a rock object and WinterShipFighter has a collusion event with the rock and the collusion has a code in it that has the instance destroy code, and every time i hit the rock the Error with come up. The game has a problem finding WinterShipFighter because it was destroyed by hitting the rock, but i don't know how to make it so it'll stop trying to find it once it's destroyed.
     
    Last edited by a moderator: Jan 21, 2018
  9. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,148
    if instance_exists(WinterShipFighter)

    Before running code based on WinterShipFighter, check if it exists first.
     
    Player12Coconut likes this.
  10. Where do I put if the if instance_exists code?
     
  11. Nevermind. Tysm! It worked!
     
  12. Nevermind, i think that’s about it that I need help for now, Tysm for helping!
     
    Bentley likes this.
  13. Bentley

    Bentley Member

    Joined:
    Jun 18, 2017
    Posts:
    823
    No problem : ) I'm glad it's working. You can private message me anytime and I'll try to help.
     
    Player12Coconut likes this.
  14. Slyferro

    Slyferro Guest

    Is there a way to make the enemy shoot whatever direction it is facing rather than at the player directly?
     
  15. Obj_Neil

    Obj_Neil Member

    Joined:
    Apr 19, 2019
    Posts:
    21
    I want to commend Bentley for his patients.

    I don't see anything in the documentation about point_direction not updating every frame, but I am going to try it. I have been looking for an easy way to make an enemy or a bullet move toward the player but not chase the player.

    I know one way i can do it is to create a variable in the bullets create event that equals player.x and y, then use that for the point it seeks, this way the point it is going to is the point created when the bullet was created, so it goes to that fixed point where the player was, allowing the play to dodge the bullet or enemy.
     
  16. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,148
    I don't know why you neck wrote this post, but whatever. you don't need to store anything in the bullet. Just specify its direction and speed in the create event or at the moment it is created. If you don't want something to change every step, then don't.
     

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