Bound To Object

0 favourites
  • 10 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • 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.

    <img src="http://img46.imageshack.us/img46/1072/lxd4.jpg" border="0" />

    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:

    <img src="http://img844.imageshack.us/img844/3289/x5nc.jpg" border="0" />

    <img src="http://img94.imageshack.us/img94/6340/pb58.jpg" border="0" />

    Thanks for reading me and thanks for your help.

    Guizmus: I can't reply to your PM, I don't have enough rep yet ;/

  • 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.

  • 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: dropbox.com/s/bo86yliy7er6fcs/Bound_2_Object.capx

    I'm going keep trying what you just said. Thanks again for your help :)

  • I coded what I told you, then cleaned a little, and it's nearly another code :/

    capx

  • 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 :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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 ^^

  • 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 :)

  • Guizmus

    thank you for your effort!

    one question:

    why do we need regenerate pathfinding obstacle map and what does it do?

  • 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.

  • Guizmus

    Thank you for the clarification.

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