destroy an object on collision if key pressed...

Get help using Construct 2

Post » Sun Jul 14, 2013 9:49 am

Hi guys . I need some help again with the events.

I would like to destroy an object on collision if a key pressed.
I mean a copy of an object.

For example:
player:on collision with other object/do nothing,go to sub event
-sub event key pressed/destroy other object

But for some reason I can't use "on collision" and "key pressed" in the same event.If "on collision" has been used I can use only "key down".
Why is that?

I have tried to use variables,but in that case all the objects destroy
Like this:

(global variable created collision = 0)
player:on collision with other object/collision = 1
collision = 1/do nothing go to sub event
-sub event key pressed/destroy other object

In this case all the objects destroy,not only collided object because the second event don't know I have collided,it knows only collision = 1.
I know I can store UID in a variable but how can I use that in event?

I can use it like this:
player:on collision with other object/variable = object.UID
But there is no event to use it like this:
destroy object:variable = object.UID
spawn other object:variable = object.UID

Anybody could help me please?

How do I destroy a copy of an object on collision if key pressed?
How do I reference to object.UID in event?

Thanks.


B
4
S
1
Posts: 28
Reputation: 406

Post » Sun Jul 14, 2013 12:30 pm

Hi @ddabrahim,

You won't be able to add the 'On collision with' & 'On key pressed' conditions into the same event. This is because they are both trigger events (learn about events here).

Each will only fire on the appropriate trigger, and two triggers can never fire simultaneously. However, you could try changing your 'On collision' trigger, to 'Is overlapping' instead!

Hope that helps.
B
33
S
6
G
7
Posts: 494
Reputation: 8,252

Post » Sun Jul 14, 2013 2:25 pm

How about adding a booleen variable to go true on key pressed and false otherwise and then require it to be true for the on collision event?
B
8
S
1
Posts: 31
Reputation: 598

Post » Sun Jul 14, 2013 2:31 pm

[QUOTE=Blacksmith] changing your 'On collision' trigger, to 'Is overlapping' instead!
Hope that helps. [/QUOTE] agreeded.
B
18
S
5
G
4
Posts: 568
Reputation: 5,079

Post » Sun Jul 14, 2013 2:55 pm

Thanks Blacksmith "is overlapping" works,but I thought it can be done somehow on collision also.

amishstripclub,variables don't help in my case,because I'm using copies of objects.So if I set a variable true or 1 or 2 or whatever on collision or key press,it knows only the value has changed and what to do if it changed.But not recognise which object need to be destroyed .Destroy all copy of the object because of the same name.

Now this is my second problem,if I make copies of objects,how to recognise which is which , which to destroy,which to spawn,which to move.if I pick UID and store it in variables seems don't work.
B
4
S
1
Posts: 28
Reputation: 406


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, ColombageEnPLS, doriHOG, mrtumbles, rustomatic, zenox98 and 4 guests