Enemys Constant moving to player

brett-nortonbrett-norton Member, BASIC Posts: 64

Hi Guys hope everyone is well.

Stuck again with a little problem if anyone could help, I have a scene about 5000 pixels wide and want to have enemy's spawn in from far sides of the screen and then move to the player and attack.

Problem is when the enemy's reach the players position they stop and dont continue to follow.

I have the usual real attributes Playerx & PlayerY constrained to player position X and Y.

Code so far -
In the enemys i have move to - PlayerX - PlayerY.

I also tried updating the PlayerX - Player Y every 0.5 seconds.

I also tried:

if Enemys position x is => - Move left
if Enemys position x is =< - Move Right

Which worked ok for a while but then decided to stop working and it also didn't seem to move actors that were way out on the edges of the scene. Any ideas??

Thanks in advance.

Comments

  • freneticzfreneticz SwedenMember, PRO Posts: 774
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    Try wrapping that move to behavior in a loop.

  • IceboxIcebox Member Posts: 1,485
    edited May 2017

    You can also do it this way

    if self.position.x not = game.player.x
    move to player.x player.y

  • brett-nortonbrett-norton Member, BASIC Posts: 64

    @The_Gamesalad_Guru Could you explain what you mean by wrapping the move to make a look please?

  • brett-nortonbrett-norton Member, BASIC Posts: 64

    *Loop

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited May 2017

    He just means to place it inside a loop. So instead of:

    Move To playerX, player Y

    It would be:

    Loop
         Move To playerX, player Y

    The reason that's needed is that the Move To behavior ends when it reaches that position. But if you have it in a loop, it's going to evaluate the end position each time based on playerX and playerY. Assuming they change values, it will move somewhere else.

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

  • brett-nortonbrett-norton Member, BASIC Posts: 64

    Ahh got it, I had never even seen this type of behaviour yet very practical. One more thing if you could be so kind, When the enemy's reach the player i want them attacking the player it looks odd when they are directly on the players location i understand that i need to put Move to PlayerX + 30 to offset them slightly.

    But as its a platformer and the player can move both ways how would i say

    move to-
    PlayerX-30 if left side and
    PlayerX+30 if right side?

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    Perhaps do if enemyX is greater than playerX, stop at playerX+30; if enemy X is less than playerX, stop at playerX-30?

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

Sign In or Register to comment.