Pathfinding: add obstacle not working

Get help using Construct 2

Post » Sat Aug 31, 2013 5:58 pm

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 :)
B
2
Posts: 5
Reputation: 160

Post » Sat Aug 31, 2013 6:16 pm

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
B
43
S
12
G
6
Posts: 446
Reputation: 6,802

Post » Sat Aug 31, 2013 8:42 pm

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.
B
46
S
14
G
7
Posts: 603
Reputation: 8,116

Post » Mon Sep 02, 2013 4:48 pm

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

Every object is set as a solid.

B
2
Posts: 5
Reputation: 160

Post » Mon Sep 02, 2013 11:25 pm

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 :)
B
18
S
4
G
1
Posts: 332
Reputation: 3,149

Post » Tue Sep 03, 2013 4:14 pm

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. Sargas2013-09-03 16:17:39
B
43
S
12
G
6
Posts: 446
Reputation: 6,802

Post » Fri Sep 06, 2013 12:22 am

@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! :(
B
2
Posts: 5
Reputation: 160

Post » Fri Sep 06, 2013 1:07 am


@statelessrich What is the inital setting on flag? Try changing it. Because I made the exact sample and it works :)Windwalker2013-09-06 01:08:33
B
18
S
4
G
1
Posts: 332
Reputation: 3,149

Post » Fri Sep 06, 2013 4:49 am

@statelessrich thats because it's not "set value", but "set boolean", it's right by it's side :D
B
43
S
12
G
6
Posts: 446
Reputation: 6,802

Post » Sat Sep 07, 2013 5:10 pm

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.

B
2
Posts: 5
Reputation: 160

Next

Return to How do I....?

Who is online

Users browsing this forum: gamecorpstudio, InfiniteRockets, jorgmaquoi, newt, sean080 and 18 guests