Bound To Object

Get help using Construct 2

Post » Thu Jun 27, 2013 8:03 pm

Hi guys,

I have tried to restrict the movement of my NPCs (blue square) to a specific zone (yellow sprite). I'm using the pathfinding behaviour to assign to the NPC a random path.



I have tried to tell the NPC to navigate in a certain volume but again as usual I struggle to retrieve the volume UID, to constrain the NPC to volume is overlapping with.

I have tried something as below, but it does not work, they are not restricted to the volume they're overlapping:




Thanks for reading me and thanks for your help.


@Guizmus: I can't reply to your PM, I don't have enough rep yet ;/
B
12
S
2
Posts: 85
Reputation: 899

Post » Thu Jun 27, 2013 8:19 pm

Hey @DoudouSupreme
Long time no see ^^
I saw that you couldn't, also saw your "bug report" about it ^^ I'll send my mail.

For your problem, please, upload a capx ^^
The problem is event 61. You think you picked the volume with the condition "NPC Is overlapping Volume" when in fact you picked both. You have to pick the NPC first.
If you don't, the overlapping condition will just pick the 2 NPCs and the 2 volumes (they are overlapping at first). Then, the NPC : Pick instance with UID will just restrict the picked NPC to the one you wanted. In the end, your "picking set" will be the 2 volumes and the NPC. I'm not sure what the function calling will send in Volume.UID, as there are 2. Not what you want anyway.

Next, you could easily just change the Find Path parameters to :
X : random(Volume.Width)+Volume.X
Y : random(Volume.Height)+Volume.Y
Making the NPC obligated to move inside the volume.

Last thing, event 62, the function picks a volume, but no NPC is specified, so all NPC are selected. You have to add a second parameter to the function (NPC.UID) and select the NPC too in the function event. You could also forget about the volume.UID, as with the PathFinding I suggested, you should be able to pick the volume with the same "NPC is overlapping Volume" condition in the end of event 62.
B
17
S
8
G
4
Posts: 461
Reputation: 6,097

Post » Thu Jun 27, 2013 9:52 pm

Hey again!

Well I tried to do what you say but I'm not sure what to change really.
I have attached the capx:

Capx: https://www.dropbox.com/s/bo86yliy7er6fcs/Bound_2_Object.capx

I'm going keep trying what you just said. Thanks again for your help :)
B
12
S
2
Posts: 85
Reputation: 899

Post » Thu Jun 27, 2013 10:09 pm

I coded what I told you, then cleaned a little, and it's nearly another code :/
capx
B
17
S
8
G
4
Posts: 461
Reputation: 6,097

Post » Thu Jun 27, 2013 11:07 pm

Thanks a lot! You taught me again lots of new things with just one capx :)

I did not understand why "random(Volume.Width)+Volume.X" worked untilI realized that you had moved the origin!

It seems I made things more complicated than they should have when trying to get the UID of the volume.


Another question for you, how does the NodeAtX ? NodeAtY works?
I suppose they are the coordinates where the sprite is heading.

And I suppose this is the index "NPC.Pathfinding.NodeCount-1" but why is it negative? I mean the first node would be something like (0 - 1), why is not crashing? Or there is a security to prevent it from being negative and makes it 0?

Thanks a lot again for your help, I really appreciate and I hope my stupid question help others too :)
B
12
S
2
Posts: 85
Reputation: 899

Post » Thu Jun 27, 2013 11:23 pm

NodeAtX/Y is the coordonates of the Xth point in the path calculated by the pathfinder. I take the last one : the destination. -1 is because arrays in js are 0-based, first element is on index 0. It can never be less than 1, because you always have a destination if the path is found.
Even if I made a mistake, let's say -2, it would return Null, equivalent to 0 I think in this case, the cross would be at 0,0, but the sprite wouldn't move, it wouldn't have any path to follow ^^
You can now see where they are heading. I couldn't correctly debug your code without adding some correct debug. The enemies were going somewhere slowly, it took decades to understand the problem at first ^^Guizmus2013-06-27 23:26:11
B
17
S
8
G
4
Posts: 461
Reputation: 6,097

Post » Fri Jun 28, 2013 12:29 am

Nice, thanks for the explanations.

Yeah it's true they're moving quite slowly, it's because I want at some point to have some kind of village :)
B
12
S
2
Posts: 85
Reputation: 899

Post » Sat Jan 25, 2014 4:32 pm

@Guizmus
thank you for your effort!
one question:
why do we need regenerate pathfinding obstacle map and what does it do?
B
15
S
6
G
4
Posts: 277
Reputation: 3,948

Post » Sun Jan 26, 2014 5:38 pm

@Roccinio It wasn't a useful here. It is automatically done on item initialization.
It is to be used when there are changes in the obstacles present on the map. If you spawn a tree and don't do it afterwards, it will let the path go through the new tree. It won't see that a wall has been destroyed either if you don't force a regeneration of the map obstacles.
B
17
S
8
G
4
Posts: 461
Reputation: 6,097

Post » Sun Jan 26, 2014 8:19 pm

@Guizmus
Thank you for the clarification.
B
15
S
6
G
4
Posts: 277
Reputation: 3,948

Next

Return to How do I....?

Who is online

Users browsing this forum: alajajm, ankas and 15 guests