How do I compare two instances of the same object, and have actions affecting each

1 favourites
  • 5 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • I've run into an issue with an agar.io clone minigame I'm implementing into my game. I have it working where if the player is 1.25x the size of an ai, the player absorbs it. However, I hit a snag when trying to make the ai be able to eat each other as well.

    The event for the player eating Ai is as follows:

    player on collision with npc | Player add npc.mass to mass

    player.mass > npc.mass*1.25 | Npc set mass to 0 (there's another event that destroys an npc when mass = 0)

    However, when I make this event affect npcs vs npcs:

    npc on collision with npc | npc add npc.mass to mass

    npc.mass > npc.mass*1.25 | Npc set mass to 0

    whenever the npcs touch each other, they both are destroyed, regardless of size. I'm assuming it's because cs doesn't know which npc I'm referring to in either instance. Is there a way to fix this? I've done a little research, to no avail. Thank you!

    Bonus question: How do I make the ai run away from the player, as well as each other npcs if they're bigger than 1.25x their own mass? They're using pathfinding and LOS. Right now I have them pathfind to a random point in the layout, but more often than not they just run right into the player, getting absorbed.

    I'd also like a little help on keeping the npcs from bunching up or chasing the same food, as well as something to detect when the food they're chasing has already been eaten by someone else.

    Tagged:

  • If the npcs aren´t in a family yet, drop them in a family (maybe the player too, but that depends) and do

    NPCfamily on collision with NPC

    How do I make the ai run away from the player

    NPC is moving along path + has LOS to NPCfamily & NPCfamily > NPC --> Find path away from enemy

    I'd also like a little help on keeping the npcs from bunching up or chasing the same food, as well as something to detect when the food they're chasing has already been eaten by someone else.

    Maybe this helps, made that for a similar question. wackytoaster.at/parachute/findNewPath.c3p

  • If the npcs aren´t in a family yet, drop them in a family (maybe the player too, but that depends) and do

    NPCfamily on collision with NPC

    Okay, that gets me a little further :) but how do I call to the unique instance variables for the big npc and the smaller npc that is being eaten. The family doesn't have an instance variable.

    Also, I'm a goon and put this in the Construct 3 section instead of Construct 2, but the same principles should apply to my issue :L

  • Yes same applies. You'll also have to shift the variable into the family

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Don't use a family,

    when "on collision NPC with NPC" will pick both of those.

    Add an event to pick the smallest of the two. then it will destroy the right one.

    I'm getting warmer, I can feel it. I got it to where the npc with the highest mass will absorb the other one, but I can't get it to see if the mass is 1.25x the smaller one, so a difference of 1 mass will result in absorption. Also, I'm not certain that the number being added to the mass is half the mass of the lower mass object, but instead adding half of the mass of the bigger being itself.

    This is the event I'm using. I had to disable the mass check or else it wouldn't work.

    =============

    BONUS QUESTION, because I don't want to spam with threads lol. I'm trying to redo my npc ai events so that they move more efficiently and realistically. Initially, I just had them picking a random instance of the food object and pathfinding to it, but I want them to chase food that is closer to them, and I want them to recalculate if the food they were chasing is eaten by someone else. I keep having a problem where they all chase the same food in a synchronous movement. I want them to move at different times from each other, to chase food more intelligently and to recognize when the food they're pathfinding to is eaten.

    Here is the event I'm using. I also tried using a state system and an identification system for the food objects, but both options didn't function. Pls halp ;-;

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