Enemy behavior: walk in 'circles' and line of sight

Hello GameSalad brothers,

After watching alot of tutorial video's I have been trying to make my own game. Now I have a few questions I can't figure out by looking on the forums or watch on tutorial video's.

I have added a picture so my gaming plan will be easier to understand.

Let's begin!
1) green is the player, red is the enemy. The player has to reach the end. The enemy walks in squares/circles following the path of the red (invisible) arrows. My first question is how to let the enemy walk in 4 different directions connected to each other? All I have seen is enemies patrolling left to right to left.

2) enemy sees the player. I want to implement a ''line of sight'' to the enemy and a ''!'' as in the picture. How do i do that? So if the player walks behind the enemy the enemy won't know but if the player walks in front of him the enemy will know. when the enemy sees the player I want to player to stop moving so that the enemy can walk over him and capture him.

3) the enemy walked over/collides/overlapses with the player. I want an animation where the enemy fights the player.

4) Change scene to game over after the enemy captured the player.

Hopefully I get some reactions!

Thank you. Gijs


  • Gizza GamesGizza Games Member Posts: 7

    Walking in circles is now fixed! The rest not.

  • ImNiklasImNiklas Member Posts: 103

    1) For this, you only need a move bahaviour that tells the actor to move in the same direction as it is rotated to, and a timer like this:
    Timer every X seconds change attribute self.rotation to self.rotation + 90 (or - 90 if you want it to be clockvise)
    You could also use an interpolate behaviour in the timer for the better looks, but then you will have to have another attribute and I'm sure you can figure out how to do this by yourself.

    2) That's actually a really good question and it was fun to solve :) What I believe would work (will try in a few minutes) is that you do something like this:

    Constrain attribute self.angleToPlayer to vectorToAngle(self.position.X-game.playerX, self.positionY-game.playerY)
    Rule when self.rotation < self.angleToPlayer + 45 & self.rotation > self.angleToPlayer - 45
    Change attribute self.playerSpotted to true

    3) Please be more specific with this one; Would it be the same animation every time? Will the enemy always win? Let me know!

    4) I don't like to use the change scene behaviour, instead I use an attribute that I call gameState. It saves a lot of loading time and I prefer it so much more! But if you don't want to do that, you can do:
    If (you detect that the game is over)
    Change scene to gameover scene.

    Hope this helped you and welcome to the community :) Good luck in the future!

  • Gizza GamesGizza Games Member Posts: 7

    Hey ImNiklas, thanks alot for your response! Sadly I can't find out how to set all these rules.. could you maybe make a screenshot how it will look in GameSalad?

    For question 3; the player (dog) gets caught because he walks in the line of sight of the enemy (pitbull). The enemy catches the player and that animation will be the same in every level. The enemy will win that moment, so it is Game Over. If the player manages to walk past him the player will win.

    Question 4; if you have the time you can maybe show the gameState attribute? The game has to be played smooth ofcourse :smiley:

    Thanks again, Gijs

  • Gizza GamesGizza Games Member Posts: 7

    When I think about it, my idea looks very similar with the Pokemon players that challenge you with a pokemon match (in my game a fight animation->then game over) in-game when you walk past them. I want that effect to happen. All help is welcome!

Sign In or Register to comment.