Following AI?

Hello all, i have a good few months of extensive experience with GS now, and so decided to try making a game. The game movement is supposed to be grid based. It is a rogue-like where the enemies only move if you are. I have movement set up with my player, and as there is no way to make a grid - that i could find anyways - i just told the player to change its position to self.positionX+40, and so on to simulate a grid. Because of this, i cant just tell the enemies to follow the player as they wont move on the grid like the player does. I'm trying to find a way to make the enemy decide which direction it would be best for it to move in based on how far away the player is. I have made the enemy track the players position, and have set up playerX and playerY attributes for the game. This is probably quite hard to understand so if you have any questions just ask. I would really appreciate any help of even just suggestions at this pint. Thanks in advance. :D

Answers

  • MonteGarganoMonteGargano Member Posts: 10
    edited January 2014
    is it on youtube?
  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    @MonteGargano -- Yes, on our GSHelper.com channel.
  • MonteGarganoMonteGargano Member Posts: 10
    if its the grid based movement tutorial, i cannot open the GS file as I'm on windows. is there a way to open mac GS files on windows or no?
  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    There's a video tutorial for that as well on our channel. ;)
  • MonteGarganoMonteGargano Member Posts: 10
    yeah i just read a forum thread. i renamed the gsuser file to a gsproj and now it works. :D thanks
  • MonteGarganoMonteGargano Member Posts: 10
    well ive adapted the code to work with my level, but i still have no idea how to make they enemies move towards my whilst following the grid. any ideas?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited January 2014
    i still have no idea how to make they enemies move towards my whilst following the grid. any ideas?
    First you need an algorithm. Then you can fill in the details with specific rules and behaviors. Your algorithm might look something like this (assume column #s increase from left to right and row #s increase from top to bottom, just like in a table):

    Enemy movement
    Each turn:
    Check player's row/col position on the grid
    If my row ≠ player's row then
         If my row < player's row then
              Move to grid square in row [my row+1] and col [my col]
         If my row > player's row then
              Move to grid square in row [my row-1] and col [my col]
    Else
         If my column < player's column then
              Move to grid square in row [my row] and col [my col+1]
         If my column > player's column then
              Move to grid square in row [my row] and col [my col-1]


    Obviously, that's just a small snippet of the entire algorithm but perhaps that will offer you some insights into completing it.

    Then if you need help with a specific step, just post your algorithm here and we can fill in the details about how to code it.



    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • MonteGarganoMonteGargano Member Posts: 10
    well i used tshirtbooth's grid based movement template.
    im aware this isnt the table grid that was mentioned before. can someone explain to me how to do the table grid, or point in the direction of a video? it would make the AI a lot easier to do. thanks for the help
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.