How do I create and position object to many copied objects

Get help using Construct 2

Post » Wed Nov 30, 2016 6:03 am

Ok,

I'm trying to create an object and position to another multiple copied objects. I tried adding for each as a condition or sub event for the every tick, but nothing seems to work, some times it only shows on one object for this case is the enemy. Any help is very much appreciated. thank you in advance


Image
B
47
S
14
G
20
Posts: 87
Reputation: 12,913

Post » Wed Nov 30, 2016 8:44 am

Try this:

On created obj_Enemy : obj_Enemy spawn obj_enemyGun on layer "game" at image point obj_enemy1.ImagePoint("Gun")
If the point always at the same place you can use Pin behavior: pin obj_enemyGun to obj_Enemy in the same "on created" event
If not you have to include instance variables: Set instance variable "parentUID" of the gun to UID of the enemy when enemy created.
Than every tick for each gun pick an enemy by his UID (=parentUID) and make what you did in your example.
The reason why your example did not work - because you created only one gun, and no matter how much guns you have they all will be at the place of the first enemy because you did not picked every gun to his specific enemy...
B
61
S
31
G
6
Posts: 125
Reputation: 7,893

Post » Wed Nov 30, 2016 10:01 am

LaroTaio wrote:Ok,

I'm trying to create an object and position to another multiple copied objects. I tried adding for each as a condition or sub event for the every tick, but nothing seems to work, some times it only shows on one object for this case is the enemy. Any help is very much appreciated. thank you in advance


Image

You need to specify which "enemygun" you want where, at the moment in the every tick you set the position of all enemyguns to enemy1 imagepoint.

This will never work the moment you get more than 1 enemygun. as it will place all of them at the same enemy. You need to either pin the gun to the correct enemy.

Here is how to do it:

Image
Image
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Wed Nov 30, 2016 10:28 pm

nimos100 wrote:You need to specify which "enemygun" you want where, at the moment in the every tick you set the position of all enemyguns to enemy1 imagepoint.

This will never work the moment you get more than 1 enemygun. as it will place all of them at the same enemy. You need to either pin the gun to the correct enemy.

Here is how to do it:

Image
Image


Thanks for the reply
Ok,
It worked if were talking about multiple copies, the problem now is that I have no control to where I want to position each copy of enemy on the layout, you know the left-click+ctrl copy and drag to where you want to place the copied object on the lay out. Also my main objective is that I want all the guns to behave like a turret pointing at the player.

Image

I uploaded the capx, so anyone out there can edit it, if they know how to fix it.
https://www.dropbox.com/s/h850ugb53o3xw0i/spawn%20create%20objects%20to%20multiople%20copied%20objects.capx?dl=0
B
47
S
14
G
20
Posts: 87
Reputation: 12,913

Post » Thu Dec 01, 2016 7:36 am

First - You dont need to pin a gun by "Position and Angle" if you want a turret, you need to pin only by "Position" to allow the gun to rotate.

Second - Try to read about containers: https://www.scirra.com/manual/150/containers
They are made for making composite objects, exactly what you need.
B
61
S
31
G
6
Posts: 125
Reputation: 7,893

Post » Fri Dec 02, 2016 12:32 pm

Yura G wrote:First - You dont need to pin a gun by "Position and Angle" if you want a turret, you need to pin only by "Position" to allow the gun to rotate.

Second - Try to read about containers: https://www.scirra.com/manual/150/containers
They are made for making composite objects, exactly what you need.


Thank you so much for advising to use containers, I literally forgot about this powerful feature in C2. Now everything's working fine.
B
47
S
14
G
20
Posts: 87
Reputation: 12,913


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, Buddhika, R0J0hound, Yahoo [Bot] and 13 guests