Can See A* 2D Physics Issue

Vaulcul

New member
I spent quite a bit of time troubleshooting trying to figure out why my Behavior Tree wasn't working... all it did was make an enemy wander and then seek the player when it could see them.

After whittling the behavior down to just the "Can See" behavior ( nothing else but a selector in the behavior tree), I found that although everything looked right in the scene and in the settings (the view angle was correctly displayed), the behavior itself would fail, even though the enemy was immediately next to the player w/ 360 viewing on and the gizmos indicated the player was within the enemy sites.

In further troubleshooting, I found that if I disabled the "use physics 2D" check box, the behavior would work... but none of the gizmos in the scene functioned after that... not a huge deal, since the behavior worked (though I'm sure it will make troubleshooting harder in the future).

I've found that this is the case when a 2D collider is present on the enemy/behavior actor... it's almost as if it's being blinded by its own 2D collider.
 
If you can tell me how to reproduce the issue within a fresh project I can take a look.
 
Justin, thanks for taking a look at this.

What I did was added a 2D Collider to a GameObject, along w/ Seeker, AILerp, and Behavior tree scripts.

Then I set the behavior for the object w/ "Can See" and placed it fairly close to whatever it is supposed to see, nothing needs to move, just the sight settings need to be within range of the static objects.

Test the scene and switch "use physics 2D" on/off before hand. Repeat w/ the checkbox in the opposite position and run the scene again.

You should notice that while the 2D physics box is checked the "Can See" behavior fails as long as the GameObject w/ the behavior also has a 2D collider on it.

If you remove the 2D collider from the GameObject "Can See" will always work.

Hope this helps.


Behavior Setup.png
 
Sorry for the wait... got distracted.

I've emailed a link with a test project to the support email address provided.

Thanks again for looking at this.
 
Okay... So, right after I sent the project link I found this post from over the weekend:


Which states that "Disable Agent Collider Layer" needed to be enabled. I checked that box in the test scene and it worked...

Then I went back to my game project and made the same change there, and "Can See" still didn't work.

Then I thought, well... maybe it's because the immediate character game object doesn't have a 2D collider on it...

So, I went and disabled the 2D collider on the "Object of Interest" in the test scene... and the "Can See" failed.

So, then I went back to my game project and pointed the "Can See" item to the actual child object w/ the 2D collider... still didn't work.

I added a 2D collider to the game character and switched the "Can See" setting back to it, thinking that it might have a problem seeing colliders that were children of the main object (this ended up not being the case)... Still didn't work.

Then I went and looked at my behavior tree structure... and changing that worked.

However, I'm confused as to why the "Can See" works w/ no 2D enabled w/ one structure, but it can't work with the same structure w/ 2D enabled.

This is the structure I was using previously:

1608238976255.png

This is the structure I ended up having to change to:

1608239008339.png

So... Why did the first structure work w/ no 2D but not work with 2D, but the second structure works fine w/ 2D?

Thanks for your patience, time, and consideration.
 
I would need to see the scene in action to understand what's going on but in both of those cases you have a Seek, Follow, and Wander task active at the same time. All three of these tasks rely on movement so it probably isn't what you want. You'll only want a single task to run at the same time, likely using the Sequence/Selector combination. To get started I would create a tree similar to this video:

This is in 3D but 2D can be done similarly.
 
Thanks Justin.

I've watched that video multiple times... I'm not sure how it's going to help me make my behavior above any better though.... The behavior is supposed to allow the character to break out of a wander to do the other two behaviors at any time it needs (thus everything is being run in parallel), the follow is following an object that always stays close to the player, without making the object follow the player directly. The seek, seeks out the player whenever the player is seen. Kept on the left, as I imagine it should be the highest priority, and should not be superseded by the follow.... (in the end, this is supposed to be similar (not necessarily the same) to the monster movement in "Zelda II: The Adventure of Link" on the overworld map) I may have done this wrong... I just didn't know any better way to do it... and what I have works "good enough" for the time being.

Still not sure why changing the behavior made it work using 2D settings instead of 3D settings. Regardless, I'm good for now, things are working well enough.
 
Top