0 Favourites

Pathfinding: add obstacle not working

  • Hello,

    I have a character (char1) who moves along a path in a tight hallway. When he enters the line of sight of another character (char2), I want him to turn around, and calculate an alternative path to his destination.

    In my event sheet, I have added to the "has line of sight" event of char2:

    char1 > add obstacle > char2

    char1 > regenerate obstacle map

    char1 > find path to

    char1 > on pathfinding path found > move along path

    Yet char1, when he enters char2's line of sight, continues past char2 to the destination. What am I doing wrong?

    Thank you, and please welcome me to the forum, as this is my first post :)

  • A wild guess. Did you set obstacles to custom on the properties of char1?

    I'm pretty sure I would be able to help you if I could take a look at the capx :D

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • My guess is that you aren't giving char1 enough time to recalculate the obstacles. That action takes some time and if you find a new path right as you start recalculating, he will still register the hallway as being empty.

    Another possibility is if you're doing those actions every tick char1 has LOS to char2. That will cause him to regenerate obstacle path and find a new path every tick which doesn't work. Try adding a trigger once to the has LOS condition.

  • Thanks for the replies. Here is my updated event sheet; still doesn't work!

    Every object is set as a solid.

    <img src="http://img.ctrlv.in/img/5224b32b22da6.jpg" border="0" />

  • Hello stateless,

    Out of curiosity, I recreated the whole design myself and run some tests. Result is: A solid object cannot use Line of sight mechanic efficiently. Perhaps it's "eye" is in the center, and thus it's preventing itself from seeing anything. So when I removed solid behaviour from char2, the example worked.

    Nice catch :)

  • when I've used solid on a pathfinding object, it wont even move, as it is it's own obstacle :D

    statelessrich, I don't think the "flag" boolean will work as intended here. you're toggling instead of setting it to true, which means that if your character as line of sight it will be set to true the 1st time, and to false the second time.

    you want to do this:

    if line of sight -> set to true

    else -------------> set to false.

  • Windwalker, my char1 does not have a solid behavior.

    Sargas, I am unable to specify the instance variable bool for a Set value action... the bool doesn't appear in the drop down list, even though it DOES exist for the object! :(

  • statelessrich What is the inital setting on flag? Try changing it. Because I made the exact sample and it works :)

  • statelessrich thats because it's not "set value", but "set boolean", it's right by it's side :D

  • Here is my new event map. The flag is initialized to true. When char1 has line of sight, it's set to false so the event cannot be triggered again.

    <img src="http://img.ctrlv.in/img/522b4feaee594.jpg" border="0" />

  • The above still doesn't work ;__;

    Any suggestions?

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