# How do I Spawn groups of objects with relative angle/offset?

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.
• Hi there,

I had a game I did in GameSalad that I'm recreating with Construct 2. The original system I had which I really liked is giving me some trouble when I try it in C2. So it's something like this:

I have a spawner object.. i want to place this object (multiple ones for that matter) and each of these spawner objects would instantiate the game objects relative to the angle and position of these spawner objects.

I was thinking about containers, but I've only used containers in very limited ways till now with one easy object.. but in this case I'm dealing with objects on multiple layers and such..

Here is a working example of what I'm talking about..

There is a floor to the truck.. there are two invisible colliders on the left and right sides to guide the boxes and a canopy layer which becomes transparent when boxes are inside..

to some degree i could hard code things to appear and disappear but i would like to make it more modular so I can easily move those spawn points where ever and whatever angle.. I just don't know how to best approach it.

Here is what I have so far.. if you hit the green button you'll be able to reset and see how randomly changing the spawn angle of the black bar greatly distorts the positions of the other parts.. but if you click enough it will be facing vertically and then everything is lined up as it should be

http://part12studios.com/temp/FredExTrouble1/

Thanks!

Caleb

• Bump. It seems there is some math in there that is needed to give a "create object" action the right X and Y coordinates.

What I need to figure out is how to find out how many pixels something is. If it's facing 45 degrees to the left.. how would I calculate how many pixels (x and y) relative to the root object.

In gamesalad there was an option of going "global" or "relative" which helped distinguish pixel coordinates. I'm not aware of how Construct 2 would handle distinguishing the two.

• I've been hacking away at this and I feel like I'm close, but there is something i'm not getting..

so I'm using the pin feature which works well with a single spawn object.. this object is one i place on the scene before runtime.. note this does not work if I create this object.. which is strange..

when the spawner starts off it creates a vehicle attachment, this vehicle attachment creates the other objects which are attached to it.. all of this works.. i can move the angle of the spawner and the object moves with it in relative space / positioning..

however, if I have two of theme on the scene.. only the first one makes all trucks move.. there doesn't seem to be a parent/child relationship between the two spawners and which items each spawner spawns.

I tried making a container for the truck, but that resulted in some errors.. not sure why, but when i grouped all of them together.. it didn't like it.

Here is the capx.. https://dl.dropboxusercontent.com/u/699 ... up%29.capx

I'm really stuck on this.. i have to figure out how to keep these things pinned and relative to each other.. and how to insure various instances of a spawner retain their parent/child relationships so each spawner and it's children operate independently.

why would an object that is spawned vs being on the stage behave differently? and regardless if there are more than one on stage, only the first one put on the screen is what effects all of them.

I don't get how to insure they know to only move in relation to their respective spawner.. notice that the truck itself spawns all the pieces correctly.. my assumption is that because a given object "creates" its relatively objects that it becomes the parent, but clearly there is something more going on to this that I don't grasp.

I almost wonder if this is a time for UDID to come into place, but I've never had luck making use of that.

Thanks!

Caleb

• ## Try Construct 3

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

Construct 3 users don't see these ads
• I made this demo http://part12studios.com/temp/FredExTrouble2/ to better show what's going on now..

you can see that there are two blocks.. one on the right is physically on the screen before the layout is run.. the black bar on the left is being created on start of layout..

both bars are doing their job creating a truck and respective parts, but then once that job is done, the bar on the left (if you click it you will see) moves without effecting the child object (i believe it's a child of the black bar) is not concerned about the parent.. instead it listens to the location of the black bar on the right.

I thought the parental thing would be established based on which object is instantiating the resulting sub-objects.

I tried using a container for the truck but when i put the respective other objects that it creates at the time of its creation.. I get a behavior error at the start of the browser.

Any tips/advice would be welcome.

Thanks,

Caleb

• 4 posts