Setting position of separate instances to one another?

Get help using Construct 2

Post » Tue Nov 10, 2015 8:10 pm

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:

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.
Posts: 4
Reputation: 245

Post » Wed Nov 11, 2015 12:17 pm

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
Posts: 327
Reputation: 6,156

Post » Wed Nov 11, 2015 3:08 pm

Thank you fisholith, this looks like exactly what I need. I'll get to work on it right away!
Posts: 4
Reputation: 245

Return to How do I....?

Who is online

Users browsing this forum: Lancifer, Sup with that? and 66 guests