How do I - Handle overlapping objects with passing time

Just started using Construct 2? Post your questions here

Post » Sat Jun 04, 2016 2:59 pm

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
Regards

TimCS
B
23
S
8
Posts: 130
Reputation: 1,917

Post » Sun Jun 05, 2016 3:12 am

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".
Ruby Winds: a top-down adventure game inspired by the Oracle series of Zelda games.
Twitter - Devlog/Site
B
14
S
6
G
13
Posts: 54
Reputation: 7,503

Post » Sun Jun 05, 2016 7:31 am

SNN135 wrote: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
Last edited by timcs on Sun Jul 03, 2016 1:24 pm, edited 1 time in total.
Regards

TimCS
B
23
S
8
Posts: 130
Reputation: 1,917

Post » Sun Jun 05, 2016 1:00 pm

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.
Ruby Winds: a top-down adventure game inspired by the Oracle series of Zelda games.
Twitter - Devlog/Site
B
14
S
6
G
13
Posts: 54
Reputation: 7,503

Post » Sun Jun 05, 2016 2:49 pm

SNN135 wrote: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
Regards

TimCS
B
23
S
8
Posts: 130
Reputation: 1,917

Post » Sun Jun 05, 2016 3:08 pm

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)?
Ruby Winds: a top-down adventure game inspired by the Oracle series of Zelda games.
Twitter - Devlog/Site
B
14
S
6
G
13
Posts: 54
Reputation: 7,503

Post » Sun Jun 05, 2016 5:01 pm

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
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sun Jun 05, 2016 5:22 pm

@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
Regards

TimCS
B
23
S
8
Posts: 130
Reputation: 1,917

Post » Sat Aug 13, 2016 2:17 pm

@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
Regards

TimCS
B
23
S
8
Posts: 130
Reputation: 1,917

Post » Sat Aug 13, 2016 5:56 pm

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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Next

Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 9 guests