News Forums RAIN General Discussion and Troubleshooting AI Character can see player through walls

This topic contains 14 replies, has 3 voices, and was last updated by  kilfeather94 5 days, 11 hours ago.

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #39429

    kilfeather94
    Participant

    Just having some trouble with the visual sensor for my AI rig. Whenever my player goes behind a wall while the enemy AI is following the player, the enemy can still see the player and will keep walking into the wall. Just wondering does anyone know if there’s a solution to this?

    #39433

    strangegames
    Participant

    I just had this problem and found that the visual sensors didn’t have “Line of Sight” checked. On my version of Rain, this setting is hidden and you have to choose “Show Advanced Settings”. To enable advanced settings, go to your AI rig in the Inspector and click on the gear icon out to the right. You’ll see the option in the drop down to change between advanced and basic settings.

    Reggie

    #39434

    kilfeather94
    Participant

    Sorry, I should have been more specific. I actually do have Line of Sight checked already. It doesn’t seem to work though. I’ve enabled and disabled the wall’s layer in the line of sight mask and it makes no difference. Also the enemy can’t seem to navigate around walls. He’ll just keep walking into the wall, even when patrolling waypoints.

    #39435

    strangegames
    Participant

    It could be an issue with the behavior tree. The sensor might be working accurately but your logic might be ignoring the results somehow. How complex is your tree?

    #39437

    kilfeather94
    Participant

    Behaviour Tree

    Here’s the structure of my behaviour tree. I pretty much followed CodersExpo’s tutorial series and the tree he created is the exact same as this. But with his, the enemy can’t see the player when behind walls, but for some reason, mine still can, even though I followed his one exactly. This is the tutorial series: CodersExpo RAIN AI Tutorial

    • This reply was modified 2 weeks, 6 days ago by  kilfeather94.
    • This reply was modified 2 weeks, 6 days ago by  kilfeather94.
    #39440

    Sigil
    Keymaster

    So these things may seem obvious but I need to cover all the bases in case something was missed:

    1) Line of sight on the sensors uses the Physics.RaycastAll call from Unity, so it will require things like colliders attached to the wall.
    2) You should enable the layers in the line of sight mask that you want to block your sight. Essentially we cast a ray and if we hit anything in those layers we consider your sight blocked.
    3) Line of sight casts from the sensors mount point if it is assigned. Is it possible your sensor is mounted on another object and is sitting somewhere else where it isn’t blocked, and telling you everything is great?
    4) Make sure you have the latest RAIN, lots of random bug fixes have occurred over the months.

    Perhaps try a simpler setup just to make sure it isn’t something funny (like a bug). Here is a really simple tree that would move towards any “target” aspect it detects:

    root
       parallel (fail: any, succeed: any)
          detect (aspect: "target", form variable: _target)
          move (move target: _target)

    I used this tree on a simple scene with a cube AI and a target with an aspect on it and I was able to block it with a little wall.

    After we figure out the sensor we’ll address the navigation.

    #39445

    kilfeather94
    Participant

    I made a quick scene with a sphere as an enemy and a cube for a wall and a cube for a player. I used that simple tree you suggested and it seems to work. Not sure why it’s not working in my other scene as I tried everything you suggested

    • This reply was modified 2 weeks, 6 days ago by  kilfeather94.
    #39454

    kilfeather94
    Participant

    EDIT: Just made a new scene and brought over my original characters that I was having issues with the AI and the enemy’s line of sight is now working correctly and he cannot see the player when the player is behind a wall. Not sure why I was having issues in my other scene, but it seems to be working fine now in this scene. Thanks for the help anyway!

    #39456

    Sigil
    Keymaster

    Not sure why that would have messed up for you, perhaps something odd was going on with the assigned layers. Just thinking out loud about what would be connected to the scene itself.

    Well anyhow, glad you got it working.

    #39531

    kilfeather94
    Participant

    Sorry for such a late reply to this thread, but just wanted to know if there’s any way of fixing this other issue I had where the enemy character walks into walls? It follows it’s patrol route fine as well as the waypoint network when wandering, but sometimes, when wandering he might get caught in between walls and will keep trying to move through them without navigating around them. Unity then freezes up after a few seconds when the character gets stuck in the walls.

    #39536

    Sigil
    Keymaster

    As long as the walls are in the Navigation Mesh your AI should avoid them. If you click on the AI you can go to the Navigation Tab (sign post, but kinda looks like a telephone post) and click the draw paths button. The drawn path should not be heading through any holes in the Navigation Mesh. If it is it means it thinks the AI or its target are off the Navigation Mesh and its trying to just head towards its target.

    #39538

    kilfeather94
    Participant

    I have some screenshots here, just to give you a better idea as to how the Navigation works in my scene. http://imgur.com/UmSeiz6 In this screenshot, the AI seems to be following the path correctly around the wall, But around halfway through the path, he’ll immediately turn and face towards the wall and try and reach the end of the path like so: http://imgur.com/7cp62fw I’ve also checked that the walls are part of the Navigation Mesh and have their own layer. Holes are generated around the walls when I generate the Navmesh. To sum it up, the main problem is, he’ll start moving around the wall and follow a path, but then he will just suddenly turn towards the wall and walk into it.

    • This reply was modified 1 week, 3 days ago by  kilfeather94.
    • This reply was modified 1 week, 3 days ago by  kilfeather94.
    #39540

    kilfeather94
    Participant

    Also, this is the code that is being used for when the character is wandering. Not sure if this is the reason why he won’t navigate around walls correctly. This code is from CodersExpo tutorial for RAIN.

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using RAIN.Action;
    using RAIN.Core;
    using RAIN.Navigation;
    using RAIN.Navigation.Graph;
    [RAINAction]
    public class WanderLocation : RAINAction
    {
        public WanderLocation()
        {
            actionName = "WanderLocation";
        }
        public override void Start(AI ai)
        {
            base.Start(ai);
        }
        public override ActionResult Execute(AI ai)
        {
            Vector3 loc = Vector3.zero;
            List<RAINNavigationGraph> found = new List<RAINNavigationGraph>();
            do
            {
                loc = new Vector3(ai.Kinematic.Position.x + Random.Range(-8.0f, 8.0f),
                                  ai.Kinematic.Position.y,
                                  ai.Kinematic.Position.z + Random.Range(-8.0f, 8.0f));
                found = NavigationManager.Instance.GraphsForPoints(ai.Kinematic.Position,
                                                                                     loc,
                                                                                     ai.Motor.MaxHeightOffset,
                                                                                     NavigationManager.GraphType.Navmesh,
                                                                                     ((BasicNavigator)ai.Navigator).GraphTags);
            }
            while ((Vector3.Distance(ai.Kinematic.Position, loc) < 2f) || (found.Count == 0));
            ai.WorkingMemory.SetItem<Vector3>("varMoveTo", loc);
            return ActionResult.SUCCESS;
        }
        public override void Stop(AI ai)
        {
            base.Stop(ai);
        }
    }
    • This reply was modified 1 week, 3 days ago by  kilfeather94.
    #39565

    Sigil
    Keymaster

    So for choosing a random location, I prefer the code in this post if you are using an RAIN Navigation Mesh as it will guarantee a spot (the loop in your action can go on for a long time if it gets unlucky I think).

    Aside from that though, send me an email at sigil@rivaltheory.com and I’ll get you a new build of RAIN. I want to make sure that it isn’t a bug that we’ve already fixed before I continue to try and debug this.

    #39575

    kilfeather94
    Participant

    I think I’ve fixed the issue. Turns out, I had the’close enough distance’ in the ‘motion’ section for the AI rig set to ‘2’. I set it back to the default value of 0.1 and the character now seems to navigate around walls just fine. The only time it might get stuck in between walls is when it’s following the player and constantly facing in the direction the player is moving. The AI might get too close to the edge of a wall when following the player and will keep trying to walk forward but may get stuck, until the player changes direction so that the AI isn’t facing near the edge of a wall. Apart from that though, the AI can navigate around walls fine now.

Viewing 15 posts - 1 through 15 (of 15 total)

You must be logged in to reply to this topic.