How do I - Handle overlapping objects with passing time

0 favourites
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hi

    I thought I had cracked this until I realised that if an "enemy" object passes over one of the "target" objects which is a clone of another, then the logic I had put in place is "enemy" overlapping "target" and system time = 5 seconds does not work as as soon as the "enemy" passes over the object while heading toward another, this logic will be triggered.

    So my aim is to only trigger the time aspect once the "enemy" object has stopped over the "target" object that it has reached. I am using the Moveto plugin for the "emeny" to move to the target and with their being two copies of the same object on the scene. I used pick a random instance for the game to decide which of the two targets the "enemy" will move towards.

    Thanks

    TimCS

  • It's a little hard to follow exactly what you're asking, especially with the timer bit. Are you saying that if the enemy is moving towards target X (for example) and it passes over target Y on the way, it triggers the event? If so, it's because you're using the "is overlapping" condition. A better alternative might be to use MoveTo's "On hit target position".

  • It's a little hard to follow exactly what you're asking, especially with the timer bit. Are you saying that if the enemy is moving towards target X (for example) and it passes over target Y on the way, it triggers the event? If so, it's because you're using the "is overlapping" condition. A better alternative might be to use MoveTo's "On hit target position".

    Thanks SNN135 that makes more sense I will give that a go instead, sorry if my post was a little confusing . The timer bit is for how long is the emeny is overlapping the target that is why I was using that logic. Would using the on hit target position and the timer logic work ? Basically I want the target to change apperance if the emeny is overlapping the target for a period of time

    ** EDIT**

    Tried using the "on hit target position" , however the issue with using the on hit target is that when changing the apperance of the target it has reached, because the other target is a clone of this one, they both change apperance as I am using the set frame action to do this.

    **EDIT **

    Just wanted to edit this post instead of adding a new post because, I have not suddenly disappeared off the earth I am just a little busy with "other life projects" at the moment .

    I do not want you to think I you have been wasting your time helping me with this. I will come back and look at this all again

    Thanks

    TimCS

  • In addition to using "On hit target position", you could use "Pick nearest <target>" in the same condition (or as a subevent of "On hit target position"). This should only change one of them.

    Let me know if that doesn't work.

  • In addition to using "On hit target position", you could use "Pick nearest <target>" in the same condition (or as a subevent of "On hit target position"). This should only change one of them.

    Let me know if that doesn't work.

    Tried you suggestion by adding pick nearest/furthest under the size/position section and used the X and Y from the enemy , this still changed both targets apperance.

    As I am using the free version I do not have access to families , with the move to action plugin, do you know if this works with families as I do not want to make the assumption that it does .

    Thanks

    TimCS

  • No, I don't think this would have anything to do with families. It should work without using them.

    Can you post a screenshot of the code in question (.capx would be preferred, but if you'd rather keep that private, a screenshot should suffice)?

  • Okay, this is what you want to do ?

    Its a bit difficult, hope the comments help. Else just ask.

    https://www.dropbox.com/s/i0rf9zl9wutik ... .capx?dl=0

  • SNN135 - I will do this as soon as I can but will need to look at what 99Instances2Go has done if that is okay. I do appreciate the help BTW and from all of the gaming makers I have tried so far, this community has been the most helpful .

    99Instances2Go - thanks for the capx file will have to spend some time to properly go through this. I should be able to understand it has I have coded applications just not games

    ** EDIT **

    99Instances2Go - I think your example looks like it is what I want but I am still working through the logic at the moment and so I did not want you to think I had forgotten about this . Work has been crazy so my head has not been in the right place

    I presume that although in your example the "enemy" moves between the "targets" I can use this logic to " for me the idea would be to have each type of "enemy" aiming at a target and if a certain time passes , the "target" appearances changes "

    ** EDIT ** 13 08 2016

    Sorry everyone for my previous edit I made as I thought I was editing my last post I made not one in the middle of the thread. I am still going to look into this and I sill appreciate everyones help just that my brain is "not in the right place" at the moment

    Thanks

    TimCS

  • 99Instances2Go

    I have had another look at your capx file again and just wanted to get my head around some of the "code" or events that you have done. I think I get the sections 1 through to 6 as you seem to be setting up the position of the targets and call all of them the same name. I presume they are called the same name to make the random targetting easier ?

    From 7 to 8 I think I get it, you are setting a random targets UID to the "mover" or my case "enemy" but then you have put in a move to , is this then moving the "mover" straight away to the target ?

    After this I get a little lost from 9 through to 19. I am sure it is straight forward but I am still getting use to the "event" method of coding from Construct. I am used to application programming as a whole but gaming programming I found to be a very different matter altogether .

    Thanks

    TimCS

  • On startup of layout (event 1), i place the targets. Because i use a container to pair up text boxes with targets, i got to create them on run time. Because i was to lazy to calculate positions, i prepared some objects in the layout to place the targets on.

    Event 7 reads as: if instance variable 'targetUID' of the mover = -1, then pick the mover, and add a random target to the picklist. Move the picked mover to the picked target. At the same time i set 'targetUID' to UID of the choosen target. I reset the 'overlappingTime' of that target. I write that (zero) in the textbox belonging to that target. Since i use containers, picking a target also picks its text box. And, so i can see (and debug what i am dooing) i set the opacity of that choosen target, so it stands out. This event (event 7) will not run again untill 'targetUID' is set to -1 again in event 15. Why -1 and not zero ? Because the UID zero can exist. It is bad coding to take that risk.

    Event 9 reads as: Pick the target by its UID (instance variable 'targetUID' of the mover). Add the mover to that picklist when its boolean 'StartedOverlapping' is not true. If the picked target overlaps the picked mover then ... and only the first tick that all this is true ... set 'StartedOverlapping' to true.

    So. When the mover overlaps that choosen target (not any other target) set a boolean to true, so we know that from this moment we have to count the time that they are overlapping.

    Event 11 is the opposite of event 9. If i set a boolean, i have to unset it somewhere.

    So, event 11 reads as: if the boolean 'StartedOverlapping' is set to true and if the mover is not overlapping any target, then pick the mover. And set 'StartedOverlapping' to false.

    Also meaning that there can be no more time added in event 13. Done with overlapping = stop the timer.

    Event 13 is the counter. It reads as: if 'StartedOverlapping' is true, then pick the mover. If that mover is overlapping any target, then add that target to the picklist. 'StartedOverlapping' is only set (in event 9) when the target is the choosen target, so i can safely asume that any target picked here is the choosen target. When all this happen, add dt to the timer every tick. And show that time in the (due the container) picked textbox.

    Event 15 just sets instance variable 'targetUID' of the mover to -1when the MoveTo plugin says it reached destiny. With 'targetUID' = -1, event 9 can again find a new target. And it all starts all over again.

    Basicaly most coding in C2 works this way: pick an object when something is true. Add another object to that picklist when something is true. Make actions that work on the picked objects.

  • Just wanted to thank you for your reply, I will need to soak it all in and may be back for questions again! I think the part that I am trying to get my head around is how the mover is moving between the target endlessly - is this because is it running for every frame of the game ? If so I would need to work out how to stop this as the movers or enemies in my game, once they have reached their target, need to stop.

    ** EDIT *** 29 08 2016

    99Instances2Go

    I have read your post and then decided to follow the logic by trying to re-create what you have done but with using my own objects. The stupid pat is I am unable to mirror how you have added stage 2 where you destory the target onto a separate line under the On Start of Layout.

    Can you please help with this?

    ** EDIT 22 08 2016 ***

    99Instances2Go

    Worked out that these are "blank sub events" will continue working on this and hopefully will understand it better when I do this.

    Thanks

    TimCS

  • 99Instances2Go

    I think I have got my head around this now, I do however have some questions on what I am trying to achieve, if they need to be a new post then let me know and I will submit a new thread.

    As I will be having multiple enemies (They will be different in apperance and may be size) moving towards the different targerts, I would need to have this block of code for each of them. Is there an easy way of doing this ?

    Also I may want to stop the emenies from heading to a target that is already "picked" by another and may allow for e.g. 2 ememies to go to the same target but no more. Can this be done as well ?

    Thanks

    TimCS

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hope this answhers all the remaining questions. I used a container to pair the text objects.

    Basecaly, all you have to do is make every variable 'personal'. Meaning: use instance variables and personal behaviours. Pick based on the instance variables.

    If the conditions pick several instances, and the actions must be private, use 'for each'. Loops trough each of the picked instances.

    https://drive.google.com/open?id=0B1SSu ... ENlSGYwMXc

  • Hope this answhers all the remaining questions. I used a container to pair the text objects.

    Basecaly, all you have to do is make every variable 'personal'. Meaning: use instance variables and personal behaviours. Pick based on the instance variables.

    If the conditions pick several instances, and the actions must be private, use 'for each'. Loops trough each of the picked instances.

    https://drive.google.com/open?id=0B1SSu ... ENlSGYwMXc

    Thanks once again for you help 99Instances2Go if Construct can work for me then I will likely be purchasing it. It has taken me some time to find a decent game maker and one that works with my budget. Some seem too expensive to me and one that I did buy lacks in support from a community like this one.

    Thanks

    TimCS

  • 99Instances2Go

    Had a look at this capx file you have done, thank for this, one question on the "badboy" object which in the case of this project is one object instances being created X amount of times. If I had e.g. 4 different objects how would I best spawn these in the same way ? I was wondering if they could all be part of a family and then spawn them if they are part of X family . Obviously I cannot test this on the free version so I would not know if that would work

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