0 Favourites

Solution to a multiple instance problem

  • 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. <img src="smileys/smiley6.gif" border="0" align="middle" />

    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.<img src="smileys/smiley1.gif" border="0" align="middle" />

    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

  • 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

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • 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   

    I too would like this. Sometimes it would be very useful.

  • Cheers for the responses (and sorry for my tardy response).

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)