Bullet owner

Get help using Construct 2

Post » Mon Jun 24, 2013 9:17 pm

Hi

When a bullet hits a player, I want to know which instance of the enemy shot it (so I can increase its experince, or something). How can I do that?

Thanks
B
7
S
3
G
3
Posts: 53
Reputation: 2,459

Post » Mon Jun 24, 2013 9:28 pm

The simplest solution is to add an instance variable to the bullet object (e.g. "SourceID"). Whenever a bullet is create, set the instance variable to the UID of the object it was spawned from. Then, whenever the bullets hits something, you can use the "Pick by UID" condition to find its source based on the bullet's instance variable.
B
63
S
19
G
8
Posts: 341
Reputation: 12,130

Post » Mon Jun 24, 2013 9:30 pm

I'd suggest that you assign Bullet an instance variable of "Parent" or something. Then, in the Bullet creation event, the correct Enemy is already picked since it's the one spawning the Bullet, so simply assign the value of Bullet.Parent to enemy.UID.

Later, when the Player is hit and killed and you want to increase Enemy.XP, pick the Enemy by its unique ID and add to its XP.

EDIT: Hah, ninja'd by @zatyka!GeometriX2013-06-24 21:31:28
B
57
S
15
G
11
Posts: 912
Reputation: 12,606

Post » Mon Jun 24, 2013 9:31 pm

Add an instance variable to the bullet called "parentUID"

When the enemy shoot a bullet, set "parentUID" to the enemy's UID

Then on the 'bullet collides with player' event, add "pick enemy by bullet.parentUID" and this will pick the one enemy that shot the bullet.

Edit: got double ninja'ed :P7Soul2013-06-24 21:32:22
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249


Return to How do I....?

Who is online

Users browsing this forum: fearfulelephants and 26 guests