How do I make a solid object find a path?

Get help using Construct 2

Post » Mon Sep 05, 2016 6:10 pm

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.
B
14
S
3
Posts: 29
Reputation: 870

Post » Mon Sep 05, 2016 6:24 pm

This thread might have your answer. :mrgreen:

how-do-i-make-pathfinding-on-solid-things_t170480
B
11
S
6
G
15
Posts: 256
Reputation: 9,207

Post » Mon Sep 05, 2016 8:23 pm

Message: Taweel can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
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:
https://jpst.it/N25y

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.
B
14
S
3
Posts: 29
Reputation: 870

Post » Mon Sep 05, 2016 9:26 pm

I tested it and it's working fine. :?

Did you add Solid to Red by any chance?

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

https://www.dropbox.com/s/04nhza5pk9a8l ... .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.
B
11
S
6
G
15
Posts: 256
Reputation: 9,207

Post » Mon Sep 05, 2016 10:36 pm

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.
B
14
S
3
Posts: 29
Reputation: 870

Post » Mon Sep 05, 2016 10:56 pm

You're always welcome, Taweel. :mrgreen:

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.

https://www.dropbox.com/s/m2qgx8ks3n045 ... .capx?dl=0
B
11
S
6
G
15
Posts: 256
Reputation: 9,207

Post » Mon Sep 05, 2016 11:17 pm

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.
B
14
S
3
Posts: 29
Reputation: 870

Post » Mon Sep 05, 2016 11:17 pm

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

Post » Mon Sep 05, 2016 11:44 pm

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?
B
14
S
3
Posts: 29
Reputation: 870

Post » Tue Sep 06, 2016 8:46 am

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.
https://www.google.be/search?q=scirra+p ... 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 (https://www.scirra.com/manual/75/how-events-work), 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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Next

Return to How do I....?

Who is online

Users browsing this forum: Fenix18 and 10 guests