How do I Make these objects act independently?

0 favourites
  • 4 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • So I have "Defenders" in a family. Then I have the "Defender Movers" which are bullet objects I attach to the Defenders to do their movement. Then I have "Detectors" which are large circles that are placed on the Defenders when they are created. The Detectors don't move with the Defenders, they are made so that the Defenders will only go after enemies that overlap inside the Detectors.

    I want to make it so when an enemy is overlapping a Detector, the Defender Mover will set it's angle to the closest enemy to it and move towards it, while the Defender Sprite is attached to the Mover.

    The problem I'm having is that only the first instance works. Any copies I make after that don't respond to enemies at all.

    I don't fully understand how to make UID's work, what I have now is basically copied from an earlier part of my game from something similar.

    Sorry for the large post, I'm not sure if there's a simpler way of doing what I'm trying here.

    Thanks for any help.

  • 2.:

    -Foreach Defender (event, auto every tick if in front, get first )

    -Pick Defendermover by id compare Defender id (get second)

    ->Defender set position to DefenderMover (work with both)

    3.:

    -Detector is overl. Enemy (event, auto every tick if in front)

    -Pick Defendermover by id compare Detector id (pick first)

    -Enemy pick nearest to DefenderMover(?Detector?) (pick second)

    ->Defender set angle towards Enemy (work with both)

    There is no need to "foreach defenders" and then "pick defenders".

    You pick first and then an other, you pick second and then an other, ...., this makes no sence.

    Another problem is you access for example: defendermover.ID before you pick a defendermover instance.

    Or are defenders and defendermover bundled by container?

    But then you can access directly, without pick.

    Hope I understand right what you want...

    Will be easier with project file.

    How UIDs work is simple.

    Every object on plattform has a unique number, always continuously.

    You use it from first to bundle objects by instance varibale, yes this is one possible.

    I am a fan of equality, so then i would give Defenders also instance var id...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey thanks for the response. What do you mean by "(event, auto every tick if in front)"?

    I'm not sure what you meant with the brackets, so I just tried the basic code without what was in the brackets. It made the second Mover follow the first Mover's target.

    I think I understand how UID's work, but in one of the tutorials it says "UIDs change if you delete and insert instances...the instance with UID 3, for example, could change to a different object if you add or delete some things in the layout view".

    This kind of confuses me because I have a code that sets an objects "ID" variable to another object's UID once when it's created, and the code still works if copies are created/deleted. I'm not 100% sure how they work and that's why I'm kind of just copy/pasting code from other parts that work.

    Anyways thanks again for the help.

  • Only a hint. (event, auto every tick if in front) Its an event, that will be triggered by tick automaticly, no "every tick" need before.

    May be the uid`s are an array, an array should not have gaps, may be if you del an object, that they will reorginized, I never had tried this out.

    But I dont think so. If you add something manual to plattform and another, and then remove the first the uid stay same...

    If you want to bypass UID, make a global variable myID=0, use this for your instances. After a create make myID=myID+1, so you have your own UID. But never forget to add!

    I would suggest you to use a conainer, then everything falls away.

    Is one object of a container is created, all will be created. If you call a instance object in a container, you have access to all instance objects in. https://www.scirra.com/manual/150/containers

    I think Defender, DefenderMover and Detector can be in a container.

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