How do I make enemies oscillate around the player?

0 favourites
  • 14 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • I saw a post about a whole ago but in 1 hour I couldn't find again so maybe someone can help me out. I got a top down game with spaceships. I will like the enemies to come towards the player and when they are in a defined range I'll like for them to start making circles around the player.

    Any suggestions?

  • for each enemy

    system compare two values: distance(enemy.x,enemy.y,player.x,player.y) => 100

    enemy - move towards player.x,player.y

    for the second part I would have a rotating sprite at the players position and pin the enemy to it (trigger once), when distance is less then 100, but there are probably better solutions..

  • for each enemy

    system compare two values: distance(enemy.x,enemy.y,player.x,player.y) => 100

    enemy - move towards player.x,player.y

    for the second part I would have a rotating sprite at the players position and pin the enemy to it (trigger once), when distance is less then 100, but there are probably better solutions..

    Thank you very much. I will try it when I get home and will upload the events when finished in case someone needs them too.

  • Okey I done something else, made a rotating sprite and assigned the enemy to use pathfinding towards an image point set at the corner. It has several drawbacks, such as if the solid state is added to the player it cannot move.

    How it looks like:

    Code:

  • I'm gonna search for a smoother and better option. Till then I'm all ears for suggestions

  • enemy now has both pathfinding and bullet behaviour..

    I don't think that is advisable..

    Please decide on how you'd like your enemy to move..

    Also I guess using pathfinding both on the player and the enemy (the enemy refreshing every 0.1 second) might not be a good move performance-wise, but you'll have to check in the debugger for that..

  • The bullet behaviour was disabled at start, sorry.

  • I created the same kind of behaviour with a simple bullet behaviour

    • once your enemy is in circling distance of the player:
    • set the enemy's direction to look at the player and imediately add an offset of 90 degrees to that angle
    • move the enemy forward

    =>because you constantly readjust the lookAtPlayer+90DegreeOffset, the enemy will always move sidewards to the player, effectively circling the player

  • - once your enemy is in circling distance of the player:

    How did you do that? I only have some complex solutions to finding the circling distance. Think you can post a screenshot of your events?

    Thanks.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You could do it through some expression in a 'Pick' event i believe

    or

    just use the Line Of Sight behaviour, that also has a range. can even be set 360 degrees if needed

    havent got the file aruond for screenshots sry

  • Thank you, I'll make it and post it

  • To get the distance from the enemy to the player use this:

    distance(enemy.x,enemy.y,player.x,player.y)

    if you want to know if this distance is less than 100 pixels use:

    system compare two values: distance(enemy.x,enemy.y,player.x,player.y) < 100

    the distance is measured in every direction so 100 is like a circle around player.x,player.y with a radius of 100px

  • Thank you very much guys.

    It runs very smoothly.

    I added a pathfinding so that the enemy will move towards the player and when it's at 250 it will rotate. There are some minor issues, such as when the enemy rotates at the 90 angle it doesn't go smoothly but instant so it's a bit eye catching. And if you move towards the enemy it can overlap the player and it will just rotate on the player's spot. Even so, it looks great and I'm sure I can find some workarounds for these.

  • Actually due to the pathfinding I had to change the 90 degrees to 89 because it was starting to get glitchy after 1 revolution.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)