Solution to a multiple instance problem

Get help using Construct 2

Post » Tue Mar 26, 2013 3:22 pm

Hi, just thought I would share a recent problem I have had, and the solution I found.

The problem was that my game had multiple instances of a sprite object. The sprite was a rock and it was a physics object.

Initially most rocks were set as 'Immovable', the idea was to have them block paths until they are moved by collision with other objects.

Hence one of the events I needed to add was a Rock collides with Rock event, with the immovable rock becoming movable thereafter.

Problem was I could find no way of acting on specifically the immovable rock in the action after the collision event. I tried assigning an instance variable 'Movable' but still had all kinds of problems. Either the collisions were detected immediately and all rocks become moveable, or the same rock would keep making itself moveable and the other would remain immobile.

The solution I found was to create a new family, which I called "RockActivators", and put the rocks in it (and other objects that would make a rock moveable). The event then became RockActivators collides with Rock and thus it became possible to reference each object separately in the actions.

It would be nice if there was a way of forcing 'Sleeping' on physics objects, which would sort this out for me. I will add that to my list of suggestions to be posted soon.

Hope this helps someone out there...

RR   
B
14
S
4
Posts: 33
Reputation: 2,283

Post » Tue Mar 26, 2013 4:10 pm

Here is an example on how to handle collisions between two instances of same object:

Evil sprites example

In your case, it seems a single event would do:

Rock, on collision with rock
-- Set rock immovable to false
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Wed Mar 27, 2013 10:00 pm

[QUOTE=RattyRat]
It would be nice if there was a way of forcing 'Sleeping' on physics objects, which would sort this out for me. I will add that to my list of suggestions to be posted soon.

RR   [/QUOTE]

I too would like this. Sometimes it would be very useful.
B
44
S
15
G
9
Posts: 1,096
Reputation: 11,013

Post » Wed Apr 17, 2013 3:54 pm

Cheers for the responses (and sorry for my tardy response).
B
14
S
4
Posts: 33
Reputation: 2,283


Return to How do I....?

Who is online

Users browsing this forum: michaelverdi and 19 guests