How do I make a solid object find a path?

0 favourites
  • 12 posts
From the Asset Store
Move around the rectangular and travel as much as you can!
  • I did a very simple path finding test where the path is "L" shaped. There is one sprite at one end of the path that spawns the enemy sprites. The Enemy needs to find a path to a sprite at the other end of the path.

    It all works fine until I add the "solid" behaviour to my enemy sprite. The enemy sprite fails to find a path!!

    Is that a know issue?

    The reason I want to use the solid behaviour with my enemy is to try to prevent the enemies from overlapping on the path.

    Many thanks in advance for you help.

  • This thread might have your answer.

  • Hi Gmoney,

    Thanks for the reply. I am not trying to find a path in solids. I am trying to make my enemy sprite "solid" then do "find path behaviour".

    Here is an image of my level/events:

    The blue lines are solid.

    Red sprite spawns Pink sprite

    Pink sprite tries to find path to Green sprite.

    This works fine if Pink doesn't have "Solid" behaviour. As soon as I add "Solid" to Pink sprite, it stops working!!

    Does path finding not work from solid objects?

    Thanks again.

  • I tested it and it's working fine. <img src="{SMILIES_PATH}/icon_e_confused.gif" alt=":?" title="Confused">

    Did you add Solid to Red by any chance?

    In this example capx file, Pink has Solid, and it can find the path well. ... .capx?dl=0

    However, when I applied Solid to Red (when Pink had Solid), Pink couldn't find the path.

    By the way, I'm using the default Pathfinding behavior settings.

  • Thank you very much for that capx Gmoney. It helped a lot.

    Your example works fine while mine (which is exactly the same) doesn't. After spending some time comparing the two files I noticed that your Pink sprite is smaller than mine. I tried making it bigger and it stopped working!!

    I tried several width/height combinations and it seems to work fine for width less than or equal to 15. Anything bigger it doesn't work. Height doesn't seem to matter.

    A sprite with width 20 should easily pass through that path.

    What I need to know now is why is this happening with width greater than 15?

    Why does making it "solid" matter for path finding?

    Why is it not the same for height?

    Any thoughts on this are highly appreciated.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You're always welcome, Taweel. <img src="{SMILIES_PATH}/icon_mrgreen.gif" alt=":mrgreen:" title="Mr. Green">

    I don't think this is a 'width/height' issue.

    I tried with (100,100) for both Red and Pink and confirmed they're working.

    Have you checked to see if Red or Green has Solid?

    Here's a new example. ... .capx?dl=0

  • Thanks again Gmoney. I did check that Red and Green are NOT solids.

    Could you please add "Destroy outside layout" behaviour to yours and try it again? On mine that seems to break it.

  • That last Capx works by accident. And here is why it works...

    First this. You can not read properties/values from a newly created object until the next new root-event. 'On create' is no more then a special function, so, it does not count as a new root-event.

    Since you cant not read its Solid flag at that point, the path does not know that is a solid. Therefor that newly created object is not added to the obstacle map. And the pathfinder sees trough it. A solution by accident, and only working under those specific circumstances.

    Just switch the solid to off before finding a path and back on during 'on path found'.

  • Thanks 99Instances2Go. Your solution seems to work.

    I am still not sure why adding an unrelated behaviour or changing the width makes a difference in this case.

    I am interested in learning more about "root-events" and when can object properties be accessed after creation. Is there a section in the manual about that?

  • I am not aware of an entry in the manual about this. I had to learn this the 'hard way'.

    You can read about this in the forum. ... ly+created

    A lot of poeple have problems with this. But once you understand it, it means nothing.

    Since i had a hard time to learn this lesson, i understand that new users bump easy on this. So i kinda take every opportunity to shine my little light on this.

    The moment you have this 'newly created objects thing' under control, and from the moment you understand this manual page (, you understand everything about c2.

    Oh and, what i call a 'new root-event' is also called a 'top-level-event' on the forum. It just means an event that starts at a zero margin, no sub.

  • Thanks 99Instances2Go. The link you provided is a great help.

    I think the "How events work" page in the manual needs to be updated to include some information about that.

  • Solids do not move, physics is a good way to make path finding objects bump off of things, a little tinkering with friction and rotation (object behaviors) may be required*

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