How do I manage multiple instances?

0 favourites
  • 13 posts
From the Asset Store
Be quick and choose the right answer for the shown equation.
  • 2 players same base difforent variable. 2 enemies, same base difforent variable.

    I want each player to pick the closest enemy. Then move towards them. I'm using pathfinding.

    I've tried pick nearest. But when using multiple instances they target the same entity.

    And then.

    When distance <= 40 stop, trigger battle boolean.

    But only one instant will stop. The other will pass get closer/ pass through its target.

  • I'm using "for each" playerbase.

    Is there a better way to identify who is forfilling the clause?

  • Without seeing your code it's difficult to tell what you are doing wrong. "For each" is a safe method to process each instance separately. But updating targets on every tick may not be a good idea.

    You might need a state machine (a set of instance variables on players and enemies). Use Timer/LOS/Pathfinding behaviors to change their state. For example, when a player is in "find_target" state, find the nearest enemy. Then change the state to "chasing" for 2 seconds. On "chasing" timer check if the target is in firing range, if not - re-enter "chasing" again. If yes - change state to "attacking". And so on.

    Look for examples and tutorials on how games like these are made.

  • Well I'm in a process of testing. 1v1, no problem. 2v1. Got it down. But I went into 2v2 3v3 ect and problems with pathing arise.

    I'll look for examples. But, like i say, 5v1 no problem. Maybe theres a comand and conquer style game I can look for.

    On start of layout

    For each playerbase

    Find nearest enemybase. Find path

    For each player base

    distance to enemy base <= 40. Stop trigger battle boolean.

    For each player base, pick nearest enemybase. Distance >= set boolean false

    For each player base, boolean is false. Pick nearest enemy base. Set path to enemy base.

    Basicly what I'm running with.

  • Yeah. Litterally that.

    For each base pick nearest enemy base.

    All the base just path to the same enemybase, ignoring other closer instances

  • And they ignored other enemy base. They will path through other enemy base. Even though they should stop whenever they are within 40

  • If you are checking the distance without picking an enemy first, it won't work correctly because the engine will only test the first enemy instance. That's why I tell it's impossible to help you without seeing your code. Please post a screenshot of the event sheet of share your project.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The distance is just a check. So, if a player and enemy meet, they engage in battle, no matter if they are pathing elsewhere.

    Sorry for the upside down photo.. slowly I'll get to grips with this forum and posting things. It's been 6 years+

    Just want to find closest enemy. Move towards them.

    In any situation any enemy and player meet (distance<= 40) stop, engage battle.

    I've got all body working indipendantly, and battle is done asides from dodging and punch turns.

    Just the pathing, and I can make a game from it

  • For what it's worth. The always pick the lowest uid target currently

  • A..ahhh..

    So, I was picking nearest enemy base from player base.

    I wanted to pick nearest player base from enemy base

    That way the enemy base is the one being used and set path to picks it.

    My bad. New day, fresh brain

  • In the last event on your screenshot you are checking the distance to base2. But you need to pick the correct base2 instance first! If you don't pick it, then the distance will always be checked to the first base2 instance only. And other base2 sprites will be ignored.

    In the first event when you are picking the nearest base2 instance, save it in an instance variable on Base sprite as a target. Then you will be able to properly pick target base2 to check if it's in range to start the battle.

  • Yup. You saying about checking the target was right.

    I posted my findings above. Just needed to swap who was checking for who to specify who was the subject.

    Massive help, in a round about way!

    Doing the individual battle code now. Then I've got a juicy system I can use for multiple games!

    Kenshi.. then dungeon keeper.. hype

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