[SOLVED] Collision of same sprite, and Variables

0 favourites
  • 7 posts
From the Asset Store
Color Variable
$4.50 USD
10% off
Easily store, modify, read and manipulate colors with Color Variables!
  • I'm stumped on how someone could get a variable from each object on a collision event When both objects are the same sprite. Then use both variables in an action.

    practical example would be two drops of water touch and combine into one larger drop.

    something like

    SpriteA has a variable called "Var1"

    <font color=blue>SpriteA</font> on collision with <font color=blue>SpriteA</font>

         system create SpriteA, set Var1 =<font color=blue>SpriteA.Var1+SpriteA.var1</font>

         Destory original two<font color=blue>SpriteA</font>

    I searched the forum for an answer with no luck. if something like this has already been asked. I apologize. any help is appreciated. Thanks

  • but wouldn't you have to set the Height,Width size to the instance var1...?

  • Yes I would if I decide to make the Resulting SpriteA's size reflect his Var1.   I'm just not sure how to get each of the the original SpriteA's var1 so that I can add them together and set the resulting SpriteA's var1

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm afraid you will have to wait for famillies for this one.

    Having the drops belonging to two famillies (like A and B) and checking for collision between A and B.

    That's the "easy way".

    After, concerning the "trickier way" it will depends on your game and how you implement it.

    If the drops are falling (vertical moving down) drops that are spawned "in line" (not randomly, but one after the other on a progressive X) you might then consider that when two drops collides, they are "neighbours".

    Considering a "for each objects" loop runs through the instances in incremential order, you could set a system in which when a

    drop is colliding with an other

    => Have a temp variable incremented (for exemple nbDrops)

    => Store the UID of the drop in an array or some global variable (DropOne for example)

    => Store the values that you want (height, width, ...) the same way (an array is advised to store all in one line, you will need two X and as many Y as you have values to store)

    Test the value of nbDrops (subevent)

    .. System nbDrops = 2

    ..=> Set nbDrops to 0

    ..=> Create the new object Drop and set its size by adding the size values contained in your array.

    Subevents pick Drop by uid

    .... Pick the first UID of the array

    ....=> Destroy drop

    .... Pick the second UID of the array

    ....=> Destroy drop

    .... blank subevent

    .... => Clean array

    This works on the condition that drops are nearby and that two colliding drops will have close/following UIDs.

    If you spawn drops in random positions you might end up with full mayehm of distant drops disappearing and bigger drops appearing widely/randomly on screen.

    If someone knows a good way to implement "recognition/separation" in the collision of two instances I'd be glad to hear it (@r0j0hound, Ashley, ideas ?)

  • No need for families. Use 'pick Nth' in subevents, e.g.:

    + SpriteA collides with SpriteA

    ----+ Pick SpriteA instance 0

    ----> (this is the first object in the collision)

    ----+ Pick SpriteA instance 1

    ----> (this is the second object in the collision)

    In each event you can retrieve the values of the specific instance. Local variables would be handy here - you can store the first instance's variable in a local variable and then use it in the second event, so you can add together each instance's variables or whatever you need.

  • Oh very nice.

    Thanks a lot Ash !

  • Thank you Ashley that's exactly what I was looking for. And now I know what Pick Nth does. Linked is a fast example of the answer. it works but seems to have a flaw in it that pops up if I don't reset a variable on the sprite "drop" So caution, it still needs tweaking.

    link to example   .Capx

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