0 Favourites

Setting position of separate instances to one another?

  • Title is pretty vague but it's all I could fit in the space provided. Basically I was following this tutorial to make a simple "back-and-forth" platformer enemy AI:

    scirra(DOT)com/tutorials/828/adding-classic-style-movement-to-your-platform-enemies

    The enemy works well, but I've run into an issue: whenever there is more than one instance of the enemy, they all no longer function. This is because every enemy relies on another sprite called "detector" that lets the enemy know when it needs to turn around and change its animation and when it should move forward. Every tick the detector is set to the position of an image point of the enemy that is slightly below and to the side of the enemy, and when it is no longer overlapping the ground, the enemy knows to turn around. However, the presence of more than one enemy means the detector is confused as to which imagepoint it should be set to, breaking the AI.

    I know questions about UIDs and IIDs are probably asked constantly here, but I'm still having a hard time understanding them after looking up questions about them for a while. Basically what I'm trying to do is spawn one detector and assign one detector to the position of every instance of the enemy (Without making completely separate sprites and events for every enemy on the layout). One detector instance per enemy instance. Any help would be appreciated, I'd include a copy of the capx but it has a lot of extraneous stuff already and I'm not in a position to upload one anyway.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Hey SandvichEater,

    By odd chance I happened to have just finished responding to another question that had a very similar potential solution, so I hope you don't mind if my response below is a little cut-and-pastely.

    Because each enemy is comprised of a collection of unique object types, (some for the image and some for the detectors), you might be able to use the "Containers" feature of Construct 2, to associate all the objects of an enemy.

    Each enemy would get it's own set of detectors that would be automatically contextually picked whenever the parent enemy is picked, and vice versa.

    Containers will work as long as an enemy only needs one of each object type.

    For instance, if an enemy has a body and two ledge detectors, all as separate objects, then you'd need the ledge detectors to each be unique objects (e.g. leftLedgeObj, rightLedgeObj), as you can't put the same object (e.g. ledgeObj) in a Container twice. At least not to my knowledge.

    Containers page of Scirra's C2 Manual

  • Thank you fisholith, this looks like exactly what I need. I'll get to work on it right away!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
132 10,996
Burvey's avatar
Burvey
Unread hot topic
0 Favourites
[Plugin] instance bank2
85 18,369
rexrainbow's avatar
rexrainbow
Unread hot topic
88 9,241
goldentreee's avatar
goldentreee