News Forums RAIN General Discussion and Troubleshooting Problem with following the player

This topic contains 12 replies, has 2 voices, and was last updated by  Draco Nared 2 weeks, 2 days ago.

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #36571

    Draco Nared
    Participant

    Hi!

    First of all, I want to say that RAIN is magnificent tool and spared me a lot of trouble making AI on Unity’s builtin Navmesh. However, I stumbled upon a major issue that I have no idea how to cope with.

    My AIPawn uses a script in which it moves to a last location of player when it loses him/her from its sight. Usually it works, but there are situations when the chosen path to the target is a floor below. In the first pic you can see that DrawPaths chose a path a floor below, while in the second it is trying to move through a wall.
    Draw Paths shows that the chosen route goes a floor belowBut the AIPawn walks into the wall
    Sometimes it chooses a way around, going down to the floor below and then to the target (like in the first pic).
    Strange route
    There are no issues in the Behaviour Tree, in 2D environment (only one floor) it works great. However, in situations like this, it goes nuts. Also, there is only one big navmesh on scene.

    Here’s the fragment of code that sets the location for the AIPawn.

    public class MoveToLastKnownPosition : RAINAction
    {
        public override void Start(RAIN.Core.AI ai)
        {
            base.Start(ai);
        }
        public override ActionResult Execute(RAIN.Core.AI ai)
        {
            GameObject go = GameObject.FindGameObjectWithTag("Player");
            ai.WorkingMemory.SetItem<Vector3>("moveToLocation", go.transform.position);
            return ActionResult.SUCCESS;
        }
        public override void Stop(RAIN.Core.AI ai)
        {
            base.Stop(ai);
        }
    }

    I don’t know what to do so I am asking for your help.

    #36572

    Draco Nared
    Participant

    [Update]
    Small update on my problem. I tested this behaviour on prepared scene and it behaves weird. When I escape to the bottom floor, on each frame DrawPath switches between two paths (images below). Maybe the problem lies in my code? Any suggestions?

    #36584

    prime
    Keymaster

    Do you have a sample project you can send that demonstrates the issue? Also, what version of RAIN?

    #36586

    Draco Nared
    Participant

    Not at the moment - there’s a lot of stuff that I need to clean up first. I’ll probably post it tomorrow. Version 2.1.10

    #36596

    prime
    Keymaster

    I can’t really tell from the scene, but it looks a little bit like you are detecting the player and then moving there. And possibly that as soon as you start moving, you lose sight of the player and the AI changes course. Possible?

    #36598

    Draco Nared
    Participant

    AIPawn patrols. When it sees the player, it starts to follow the player. The player hides, Custom Action with MoveToLastKnownPosition executes and then it goes to the position it gets from this action. Something like this:
    -PlayerVisual != null
    —isSearching = true
    —Move (Target: PlayerVisual)
    -PlayerVisual == null
    —if(isSearching)
    —-Sets last position of Player to MoveToLocation (Custom Action with MoveToLastKnownPosition script)
    —-Move (Target: MoveToLocation)

    • This reply was modified 2 weeks, 3 days ago by  Draco Nared.
    #36600

    prime
    Keymaster

    Hmm. I still probably need to see an example project to really help…

    I wonder, though, if this would work better if you didn’t use a custom action. Instead set up your detect like this:

    SEQUENCER (repeat forever)
    — DETECT (detectedPosition)
    — Expression (playerPosition = detectedPosition) (evaluate to Success)

    and then always move to playerPosition. The playerPosition variable will always hold the last detected position, and will only get updated when the detect node succeeds.

    #36602

    Draco Nared
    Participant

    As I told you earlier, BT works fine: there are no problems with detection of Player, moving towards Player and moving to place where Player disappeared; there are no issues, AIPawn does exactly what it is supposed to do. The only problem I have is with generating path to the last known position of Player when Player is no longer detected by AI Visual Sensor.

    I tested the behaviour again and my custom action is (I’m 90% sure) not where the problem lies. However, it turned out that the second issue (with switching graphs) was happening due to my stupidity - the planes were on IgnoreRaycast layer. xD When I changed it to Default, all started to work perfectly.
    On the other hand, the problem with switching graphs showed me that Graphs were drawn on navmesh on both planes (simultaneously). When Player moves to the bottom plane, I think AIPawn should move on the graph leading to the bottom plane, not try to draw second graph on the top plane as well. I don’t know why it does it - it’s like it wants to move to Player location with ignoring the Y parameter of Player’s Vector3 position. I can send you the sample project with this strange behaviour if you want.

    What’s more, when I was looking for the possible explanations (and probable causes of this strange graph generation) in the problem described in my first post, I changed how Navmesh was generated and this way I had third layer of navmesh in the section of the scene. The navmesh generated a layer on the ceiling between two floors:
    Navmesh layer
    Floor
    Navmesh layer
    Ceiling
    Navmesh layer
    Floor
    … what made me thinking that the cause of this problem may be hidden somewhere in the scene. It also showed me why waypoints where behaving strangely there (they were dropping to the surface of ceiling’s collision, not the first floor’s). I hope that I will find it because, due to the fact that there are lots of assets, I can’t send you a sample scene of this problem at the moment - I would have to switch many things to Unity’s cubes and planes and capsules etc.

    • This reply was modified 2 weeks, 2 days ago by  Draco Nared.
    • This reply was modified 2 weeks, 2 days ago by  Draco Nared.
    #36607

    Draco Nared
    Participant

    I think I might have found the cause - it was navmesh generation settings.
    It turned out that Player’s collision radius was smaller than Navmesh’s Walkable Radius and Player could enter areas where there was no Navmesh on. When I entered such area, AIPawn detected me but decided to go to the bottom floor which had Navmesh in the same XZ spot, ignoring the Y parameter (like Vec3(0,2,0) and Vec3(0,0,0) was the same for it). Here’s the visualisation:

    As you can see, Player is standing on unwalkable cube, so AIPawn, which detected Player, walks to the spot right below Player.

    So, the solution would be to regenerate the Navmesh with Player’s collision radius or to make Player’s collision bigger (or both). Anyway, that might solve my problem, will tell later after testing. :)

    • This reply was modified 2 weeks, 2 days ago by  Draco Nared.
    #36614

    prime
    Keymaster

    A couple of notes:

    1) I wasn’t trying to suggest that the problem you are seeing would be solved by a change in the behavior tree. I was just pointing out that you are unnecessarily dropping into custom code.

    2) Sounds like this problem wouldn’t occur if the player stepped onto an unwalkable area on the bottom floor. Only if the player steps onto an unwalkable area on the top floor that has a walkable area directly below it. Is that true?

    #36616

    Draco Nared
    Participant

    1) Sorry for misunderstanding you, then.
    2) I tried to do that aaaand… guess what? AIPawn walked upstairs to the top floor. Seems like it doesn’t mind Y parameter as long as XZ are ok.

    #36618

    prime
    Keymaster

    We’ll spend some time thinking about the best way to solve this issue. I understand that you have a workaround for now (essentially keeping the player on the navmesh too) but there should be a way to keep the pathfinder from choosing the wrong path, as in your screenshot.

    The issue has to do with determining a max vertical offset for locating an object. Since RAIN allows objects to be significantly above the navmesh, it assumes the player is (from a nav perspective) actually located on the ground floor in your example, because that’s the nearest navmesh location directly below the player.

    #36626

    Draco Nared
    Participant

    Yup, I have a workaround - just keeping the player inside navmesh.

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

You must be logged in to reply to this topic.