"Can See Object" doesn't seem to be working as expected in 2D.

grimreper10977

New member
Hello,

I'm trying to use the Can See Object task to make a 2D enemy turn around when it "Sees" a wall like object. I have attached an image showing the FOV view cone and the Can See Object settings. If anyone would like a video of the problem in action I can also post a video as further clarification. However, I'll describe the issue below for now. The greyed out branch is disabled and is how I got this to work without the Can See Object, so it can be ignored for this question.

As can be seen in the image, the can see object is set to use 2d physics and I've modified the FOV angle to be 180 degrees so that presumably the enemy will be able to see objects on either side of it. I've set the initial velocity to -5 so the enemy moves to the left. My intention is that the tooth on the left will come into view, and the velocity variable will be multiplied by -1 and set as the new gameobject veolocy thus moving it to the right. This DOES work for the tooth on the left. However when the enemy reaches the tooth on the right, it does not flip. It just collides and keeps trying to move to the right. It also does not work when I set the initial velocity to be 5 (so it starts moving towards the right) so it has nothing to do with the second flip failing for some reason, it's an issue with "seeing" an object on the right. Additionally, I've tried then moving the enemy to the left of the left tooth which had previously worked, yet that still does not cause it change direction. The Can See Object task never becomes successful when the enemy is moving to the right, UNLESS I also move the cone to the right using the x offset. When I do this, the enemy does flip and bounces back and forth between the two teeth. It seems to me as if somehow only the left side of the FOV cone is registering as "seeing" and what the cone seems to overlap is not correlated to what is being registered as seen.

Based on the settings I have shown in the image, should the Can See Object be able to "see" objects on either side of this enemy?
Has anyone else experienced the view cone not seem to be accurately representing what the Can See Object task is "seeing"?
Am I missing something obvious?

Any help is appreciated as I've spent the last few hours playing with this trying to make it work. I haven't had any luck searching online for an answer. All the videos I've seen of this task seem to work exactly as I expected, but these are all in 3d games, while this is 2D. If anyone needs any further explanation/information or a video of the issue I will be happy to provide.

Thanks.
 

Attachments

  • Behavior_designer_can_see_object_broken.JPG
    Behavior_designer_can_see_object_broken.JPG
    189.7 KB · Views: 7
Is Can See Object being reevaluated? What does your tree look like when it is active?
 
It should be being reevaluated as I have it set to lower priority and it works when moving to the left, and changing only the velocity direction causes it to not work on the right. I can see when it runs that the Can See Object never returns success for the right, it always evaluates to failure. I can post an image/video of the tree running later today if that is helpful to see.
 
Here is the game running for some further clarification. Here you can see the view cone is clearly overlapping the tooth, and the sequence task is set to lower priority, yet the Can See Object is not returning successful. This exact same setup, works if I have the enemy move to the left, it will see the tooth on the left. Both teeth are the same prefab with the same tags and colliders.
 

Attachments

  • Behavior_designer_can_see_object_broken_running.JPG
    Behavior_designer_can_see_object_broken_running.JPG
    191.8 KB · Views: 5
It looks like you are restarting your tree each frame which in this case I recommend using conditional aborts. That should not affect Can See Object though. What object has the Collidable tag?
 
All of the teeth in the scene have this "Collidable tag", they are all copy and pasted from the same initial one that worked.

I do have an update though, after playing around with it some more, I did get this to work mostly as expected by checking the "disable agent collider layer" in the Can See Object inspector settings. I have no idea why this fixes the issue, or what it changed about the situation, but it now seems to work with all other settings being the same.
 
Ah, that's good news. It sounds like the raycast was colliding with itself which was preventing the check from accurately occurring.
 
Top