How do I track an event after an object bounces off another

0 favourites
  • 4 posts
From the Asset Store
Bouncing ball
$9.99 USD
Template for a bouncing ball game, fully documented in comments and video
  • Howdy C2 community - I'm pretty new to this so excuse my lack of correct lingo and rudimentary manner of explaining my request - I am trying to keep it simple without using terminology that may be misleading.

    What I am looking for is an example capx. and brief explanation of the "how" it works - I am working through the C2 manual, tutorials and examples (which are awesome) at the same time to educate myself but am getting a little stuck on this point (example below) which is distracting me from progress.

    Scenario 1 - which works 100%:

    Send a sprite (a seed) from a start location (x1, y1) to a destination location (x2, y2) and mark destination with a "marker" sprite (a hole).

    On arrival at destination that seed turns into a flower if it reaches its own hole.

    I can mark multiple destinations and keep each seed tracked to its own hole (so seed 1 = hole 1, seed 2 = hole 2 and so on by using UID's) .

    Rule: seed 1 cannot go into hole 2 and so forth.

    Scenario 2 - where I have an issue

    When a seed is on its way to its hole a kite (sprite) may block its path.

    On collision with the kite the seed bounces off the kite.

    The seed shrivels up and disappears after a short "wait" period. ===> all works up to this point

    When the the seed disappears it's hole should fill up with sand.

    What happens is that all holes on the screen fill up with sand : /

    I would have thought that the same logic I use to track the seed to its hole would hold but it does not.

    Any suggestions?

    If a capx is required I will upload if needed.

    Thanks in advance!

  • When you create an instance of an object, you have to know at that moment how you gonna pick it.

    Therefor you need a way to identify it.

    It does not matter where you create it, in the layout (a copy) or during runtime (a create action).

    This is the most basic way to do this:

    Make 1 flower in the layout. Give it a instance-variable with the name 'nr' and make it 'numeric'. Give that as value '1'. Make a copy and change the value in the copy to '2'. '3' in the next one ... and so on.

    You can assign those values also in an event.

    For the holes that would be: Make one hole in the layout. Give it a instance-variable with the name 'nr' and make it 'numeric'. Then when you create a hole in an action-event, you assign a number to that variable right after the create action. Add action > set value > instance variable is 'nr', value is the 'number'. Usaly you create that 'number' with a loop.

    Now it is easy to pick. If you want to do something with hole nr 6, then make a condition like this:

    system > pick by comparisation > object is 'hole' > expression is 'hole.nr' > equal to > value is '6'.

    Now the system picks the hole with instance variable 6, and everything you do in an action wil only be done to that hole.

    Greetings.

  • If you're using uids you could do this:

    on seed destroy

    pick hole with uid seed.hole

    --- fill hole

    But this would probably be simpler:

    +---------------------------------------+
    | start of layout                       | seed: destroy
    |                                       | hole: destroy
    |                                       | flower: destroy
    +---------------------------------------+
    +---------------------------------------+
    | start of layout                       | create hole at (random(640),random(480))
    | repeat 10 times                       | create seed at (random(640),random(480))
    |                                       | seed: set targetHole to hole.uid
    |                                       | seed: set angle toward (hole.x,hole.y)
    +---------------------------------------+
    +---------------------------------------+
    | seed: collides with kite              | seed: bounce off kite
    |                                       | wait 1 second
    |                                       | seed: destroy
    +---------------------------------------+
        +-----------------------------------+
        | hole: pick by uid seed.targetHole | hole: fill
        +-----------------------------------+
    +---------------------------------------+
    | seed: collides with hole              | seed: destroy
    | seed: targetHole = hole.uid           | create flower at (hole.x, hole.y)
    +---------------------------------------+[/code:1rfby4yt]
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Solved - another example of the awesome support from the community! Thank you very much for quick and simple responses..

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