How to choose enemies in LOT range and damage them after UID sorting?

Not favoritedFavorited Favorited 0 favourites
  • 12 posts
From the Asset Store
A master sorting Puzzle fun and addictive puzzle game! A challenging yet relaxing game to exercise your brain!
  • Hello friends! First of all sorry for my bad english...

    I'm trying to find a way to choose enemies in range by "line of sight" and damage them using there UID.

    I made a project with all mechanics that I can and can't fix.

    1) Check Distance. How to check distance to closest enemy?

    2) Choose closest enemy after distance check (works fine with LOT, but it's interesting to know where I'm making mistake without it)

    3) Choose all enemies after distance check (here is a lot of problems that I could't fix

    4) Land mine

    Here is a "c3p" https://www.dropbox.com/scl/fi/rs8zz7jnfkprt1allmoy3/Choose-Enemy-2.c3p?rlkey=agvoupl51yntnc5ued5ftn27u&st=bm7y45o8&dl=0

  • Don't use expressions like distance(Player.X, Player.Y, Enemy.X, Enemy.Y) without picking the enemy first!

    And you don't need distance() at all if you have "Line of sight" behavior. Just configure its settings correctly:

    You can also add several "Line of sight" behaviors to Player sprite with different settings. For example one for detecting enemies at short distance, another for long distance, another that ignores obstacles etc.

  • dop2000

    Your advice about pick enemy first worked and solved all my problems about picking and damaging one enemy, Thank you!

    After many tries I can't find solution for multiple picked enemies. I don't understand how to damage picked enemies using function. (maybe secret in taking parameters for function? But it can be only variables...) I don't know...

    Now it's picking multiple enemies but killing them only one by one... Why its not working for all enemies in the range and how can I fix that?

    Idea is:

    1) First enemy steps on the mine

    2) Mine check all enemies in range

    3) Damage them simultaneously (ideal version will damage enemy with coefficient of range: first enemy takes 100% or damage x 1, the last one of the mine blast radius gets 10% or damage x 0.1)

    updated c3p https://www.dropbox.com/scl/fi/mnkvc391xrmvnzxfsj206/Choose-Enemy-3-copy.c3p?rlkey=9y7k3raphqwaqye433glk501g&st=tja0kyh0&dl=0

  • LineOfSight can pick multiple instances. If you need to process them one by one, use For Each loop. You can add another parameter to the function - the amount of damage to deal, based on the distance.

    Mine has LOS to Enemy
    For Each Enemy : Call DamageEnemy(Enemy.UID, 100/distance(Mine.x, Mine.y, Enemy.x, Enemy.y))
    

    Also, you don't need LineOfSight check in "Enemy On collision with Mine".

  • dop2000You saved me so much time, thank you!

  • dop2000 When I'm triggering mine with a keyboard key, it's working like expected. What I was trying to do is: after the first enemy triggers mine, all enemies in the LOT radius are taking damage. Why it's not working if the first check is on collision; that will change the state to true, right? Plus, there is one more check to see if there are more enemies in the range, and only after that should they get damage. Where am I making a mistake?

    .c3p https://www.dropbox.com/scl/fi/xwdtdss75wrn89sjzk1xz/Choose-Enemy-4-copy.c3p?rlkey=cwwpf4xgmrcpaatqjmdbt60td&st=fvvn197q&dl=0

  • "Enemy On Collision with Mine" event picks one enemy instance. You can't pick other instances in the same event, unless you use "System Pick All" condition.

    For example:

    Enemy On Collision with Mine 
     System Pick All Enemy
     Mine has LOS to Enemy -> Deal damage to all enemies in range
    

    Another option is to call a function, which will pick the enemies in mine range:

    Enemy On Collision with Mine -> Call MineDealDamageToEnemies(Mine.UID)
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • dop2000 Awesome! Now I understand. So first was picked enemy that was on collision and thats why we need to "reset it" to pick all and after that pick some enemies within all and than do actions, nice!

  • Yes! Once you understand picking, programming in Construct becomes a breeze!

  • dop2000 Hello, in case we are using for each. That means for each instance of the object, the same action will be done, right?

    Looks like I didn't understand that topic enough. If we have a global variable "gold=0" and an enemy with an instance variable "goldReward", let's say "5" and after picking that instance we make an action like adding "goldReward" to "gold" that will work, but we are doing the same thing with for each. It's working only once even if there were 10 instances of the object picked before for each... I hope you understand my bad explanation... 

    C3P https://www.dropbox.com/scl/fi/4jfi56rjic4my2m5qwqj3/Choose-Enemy-5-copy.c3p?rlkey=iuaa4ya4gayeap0yq5vsa5f78&st=77pkq2il&dl=0

  • Say, if 5 enemies were killed at once, the condition "enemy hitpoints<=0" will pick 5 enemy instances. But Enemy.rewardGold expression inside this event will only apply to the first instance among those 5.

    So yes, in this event you need to add "For each enemy". This will process all 5 enemies, one instance at a time, adding their rewardGold to the global variable.

    By the way, this event #40 will run on every tick, which is not good for game logic and performance. I suggest making a function EnemyDeath and calling it when damage is dealt to enemies.

  • That's a very good point about every tick. I was thinking that "System / Compare Variable" initiate only on variable change. Now all of them and "for each" are replaced with functions and called after they are triggered. Everything finally works, thank you so much, Sensei!

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