Enemys Constant moving to player
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
Try accelerate toward playX,Y
Homepage: freneticgamez.eu/
https://play.google.com/store/apps/developer?id=FreneticGamez
Try wrapping that move to behavior in a loop.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
You can also do it this way
if self.position.x not = game.player.x
move to player.x player.y
@The_Gamesalad_Guru Could you explain what you mean by wrapping the move to make a look please?
*Loop
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
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?
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