How to change text for only selected instance on collision with bullet?

0 favourites
  • 6 posts
From the Asset Store
Simplistic hyper-casual game with nature elements. Tap to switch between the 4 elements and reach a better score.
  • I've creating an instance of the object each second. Also I have a text object to show health of each instance. But when instance in collision with bullet the texts counters are decreased for ALL instances. How to make it work only for that one which in collision?

    Note: health works fine for each instance, I've set 7 times to destroy and it works good, just don't know how to update texts accordingly

    Video of the problem - screencast.com/t/CNaHRtPJ

    Tagged:

  • You need to pick the right text that is linked to the Police that collides with the bullet. You can do this by putting them in a container so that when you pick the police it will pick automatically the text object.

    Alternatively, you can pick the text differently if you dont want to use containers, how did you pin the txt to the policemen? If you use Hierarchy then you can just do:

    PolicemanPick child Txt object

    You do this after the collision in a subevent

    Update:

    Also, you have many issues with your code not related to the txt issue:

    1-On collision is the same as overlapping but triggers once so you dont need to check for extra overlap on your second condition you can remove that.

    2-On collision already picks the policeman so you dont need to save the UID and picked again as it will maintain the picking throughout that scope including subevents, so you can remove that too.

    3-Trigger once you dont need it swell as the "On Collision" is already a trigger once, any actions you have there it will run just once.

    Here is how it should look:

    On Collision:----------- substack 1 from health & destroy bullet

    ----Sub: Hierarchy Pick child txt: ----set txt to policeman health

    ----Sub: Policeman Helath <= 0 ------ Your Actions

  • Thanks for the reply. I'm a noob in coding so far, so I'm sorry for stupid code and questions)

    For some reason if I add text to Police container it creates 2 polices and explodes them when created as they overlaps each other - screencast.com/t/4piz4ZxuW

    I pinned text to police using Pin behavior, without Hierarchy.

    Also Updated the code using your suggestions (if I understand them correctly)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here is how it should look:

    On Collision:----------- substack 1 from health & destroy bullet

    ----Sub: Hierarchy Pick child txt: ----set txt to policeman health

    ----Sub: Policeman Helath <= 0 ------ Your Actions

    I tried this way and now the counter always shows 7. Maybe something wrong with my code..

  • Thanks for the reply. I'm a noob in coding so far, so I'm sorry for stupid code and questions)

    No worries, there are no such stupid questions, we've all been there. Ask as much as you need. The people that ask questions learn quicker))

    For some reason if I add text to Police container it creates 2 polices and explodes them when created as they overlaps each other:

    When you use the container remember that:

    1-If you spawn the policeman then the Txt will be created with it

    2-Or vice-versa if you create the text the policeman will be created with it.

    And if you destroy one of them then the same thing happens both get destroyed.

    So basically just spawn the Policeman and the text will be created automatically.

    You can read more about containers here:

    https://www.construct.net/en/make-games/manuals/construct-3/project-primitives/objects/containers

    I you use containers then you dont need to pick using the Hierarchy as when you Pick any of the two objects (Policeman or Text) it will pick the other ones inside the container automatically.

    Here is an example with containers:

    https://www.dropbox.com/s/e164gx8uigrr1z8/Containers.c3p?dl=0

  • Thanks a lot! Added one action (Add Child) and now works as I wanted. Will try also to do using container. Thank you for the help and amazing example!

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