News Forums Search Search Results for 'line of sight'

Viewing 15 results - 1 through 15 (of 75 total)
  • Author
    Search Results
  • #39592

    Sigil
    Keymaster

    Sorry for the late reply.

    Likely the easiest route for this is to make a custom action that tests the point. Something like this (untested but compiles):

    using RAIN.Action;
    using RAIN.Representation;
    using UnityEngine;
    [RAINAction]
    public class TestLOS : RAINAction
    {
        public Expression TargetVariable = new Expression();
        public override ActionResult Execute(RAIN.Core.AI ai)
        {
            if (!TargetVariable.IsValid)
                return ActionResult.FAILURE;
            // Unfortunately, this will return Vector3.zero in the event that the variable
            // isn't defined, so you may have to watch out for that
            Vector3 tTarget = TargetVariable.Evaluate<Vector3>(ai.DeltaTime, ai.WorkingMemory);
            Vector3 tTargetVector = tTarget - ai.Body.transform.position;
            // Cast a ray from our position to the target (adding a little in case we are a little off)
            RaycastHit tHitInfo;
            if (Physics.Raycast(ai.Body.transform.position, tTargetVector, out tHitInfo, tTargetVector.magnitude + 0.1f))
            {
                // You will have to judge whether you hit something in the way, or hit the object itself here
                return ActionResult.FAILURE;
            }
            // Ray didn't hit anything so we must have line of sight
            return ActionResult.SUCCESS;
        }
    }
    #39576

    kasperfm
    Participant

    I now tried to make an Aspect with the position of my Vector3, and attach it to my AI character… I don’t know if this is the right way to do this, but I’m still having problems with knowing if the Vector3 point is in visible range / line of sight.
    Maybe I should make a custom sensor, but don’t know how to do this correctly.

    I hope someone can help me out, or point me in the right direction :)


    kasperfm
    Participant

    I made a custom action that finds a random point on Unity’s NavMesh within a range..
    But how can I detect the line of sight to that point, using RAIN? :) I already have the Vector3 point as a RAIN variable.

    #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!

    #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.

    #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.

    #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

    #39223

    In reply to: Custom action


    Sigil
    Keymaster

    1) Select “Show Advanced Settings” from the component menu (gear icon, upper right of AI Rig component). Line of sight should show up after that.

    2) The audio sensor will only check audio aspects that fall within its range. For any audio aspect within the range it will check if the audio clip is playing, if the sensor is within the max distance of the audio clip, and if the volume of the audio clip is over the volume threshold (given the range and falloff of the audio clip).

    So using your example: If the audio clip can only be heard 5 meters away, the audio sensor will only detect it when it is 5 meters or closer, even if the range is set to 30. The range on the audio sensor is just to keep us from having to flip through all the audio aspects in the scene… in a future version we may remove it and rely solely on the audio aspects and the associated audio clips volume range.

    #39212

    In reply to: Custom action


    Stream
    Participant

    Could you please answer these questions about sensors

    1. The Visual Sensor, it looks like it’s doing distance or range check + Vector angle calculation, and not a raycast? because it also detects the Target even when it’s behind a wall. Normally, how do you make it a realistic visual Line of Sight in that case? (The outdated? doc mentions it, but I couldn’t find it among Visual Sensor setting)

    2. The Audio Sensor, does it get triggered if the Aspect comes within the Range and plays any sound, or is it just like a Visual Sensor that it detects Aspect regardless of whether the Aspect is playing any sound or not?

    Now let’s say the Aspect is within the Audio Sensor range, but the Audio clip’s range is NOT actually reaching the AI for eg:

    I mean, the Audio sensor range say is set to 30, the Aspect is just in that range (eg. 25 units away), but the Audio Clip is supposed to be heard say at the distance of 5 only.
    Will the AI still detect it? (I have no actually worked with sound so I am not sure and asking you)

    Thanks

    • This reply was modified 3 months ago by  Stream.

    LudwigVanKinder
    Participant

    Hi! You’ll see, i hope you can help me. I’m pretty new to coding & behaviour trees, so i’m having a hard time trying to fix this…
    I have an IA and a First Person Character controler, the behaviour i wan’t is that the IA should patrol & when he sees the player, go after him while he can see him, this works ok, problem is that when he’s out of his vision range & line of sight he goes inmediatly back to the patrol, this is an specially noisy thing since there are tons of narrow corners, props & stuff that causes this issue to be very frequent. This is my Behaviour Tree, which is not working:

    beforehand, thanks!:b


    Sigil
    Keymaster

    Here’s the original options:
    – Select to a random location.
    – Make sure it is in the bounds of the NavMesh.
    – Move to that location using Mechanim walk animation.
    – Once at the location, load the Mechanim idle animation.
    – Pause for a few seconds.
    – Pick another target location.
    – If the player is within line of sight, head in that direction.
    – If the player is within 1/2 of the sight distance, load the Mechanim run animation and move at double speed towards him.
    – If within close proximity, play Mechanim attack animation.
    – If player escapes line of sight, pick 6 random locations around the last known position of player and search.
    – Nothing found, resume random wandering.
    – If a food item is in sight, head towards it.
    – If 1/2 distance, run.
    – If within close proximity, play Mechanim eating animation for 10 seconds.
    – If player comes by while eating, ignore player unless attacked.
    – Resume random wandering.

    So the way that I normally handle locomotion animation with RAIN is that I create an Animator Controller that handles it and either use triggers or the Mecanim Motor to forward parameters that set it up properly. Here is the pseudo code for the state machine I would set up for your AI:

    Idle (Base Layer.Idle)
        transition to Walk if Speed (float) > 0 
        transition to Attack if Attack (trigger) is true 
        transition to Eat if Eat (trigger) is true 
    Walk (Base Layer.Walk)
        transition to Idle if Speed (float) < 0.1
    Attack (Base Layer.Attack)
        transition to Idle when done
    Eat (Base Layer.Eat)
        transition to Idle when done

    So the parenthetical name on those states is the full state name that Unity (and RAIN) recognizes and we’ll use it later. So that describes the state machine. The initial use of this state machine is to set our AI up with a Mecanim Motor, and forward the Speed parameter and leave the name as Speed (given the example so far). So at this point, if we were to define a simple behavior tree that simply moved the AI across the world, the Speed parameter would be forwarded and we should see the Walk state play. You could adjust the speeds appropriately to reduce sliding, or use root motion to get rid of it altogether.

    Next up: the initial behavior tree I would setup.

    • This reply was modified 3 months, 3 weeks ago by  Sigil. Reason: Fixed random things
    • This reply was modified 3 months, 3 weeks ago by  Sigil.

    Sigil
    Keymaster

    For the options you are missing, we added a Show Advanced Settings in the component menu, it is probably where a lot of your missing options are (including line of sight). Once you turn it on all of the RAIN components will show the additional options, as it’s a global setting.

    I’ll get back here with some examples as well (I haven’t forgot), just a bit busy at the moment.

    A quick question for you, are you using root motion with your animations?


    Mad_Mark
    Participant

    I would greatly appreciate any help you can offer, Sigil. Pseudo-code that outlines the node types, settings, and parameters would be a better start than I have at the moment. I don’t mind doing the work, but lack the understanding. I’ve tried to build what I can from outdated YouTube materials, but when options aren’t present, or the UI varies, it can be quite confusing. For instance, where is the “Line of Sight” option? Is it now inherent in the Visual Sensor by default? Many of the videos I find also show a ton of parameters or options that are not exposed in my version (2.1.11.0).

    I am hoping to create this TPS Zombie game for my grandkids by Christmas. I have created 3D models of them, modeled their house and neighborhood, and have dropped them all into a rather dark place. (By request. They love The Walking Dead…) Currently AI is controlled by script, and it is getting more and more complex. I was hoping RAIN would clean that up a bit, and allow me to move further along with the AI to simulate intelligent actions.

    Thanks,
    Mark


    Mad_Mark
    Participant

    I’m down to my last few strands of hair. I have looked at the Starter Kit, and it doesn’t seem to help since the AI included are VERY skinny examples. Are there any examples of actual working functional AI that can be downloaded and examined, modified, or just straight out poached?

    I am simply trying to get what I consider the basics working. I have tried everything I can think of, read the entire WIKI, combed through the Forums, and just don’t get it!!
    My AI should:
    - Select to a random location.
    - Make sure it is in the bounds of the NavMesh.
    - Move to that location using Mechanim walk animation.
    - Once at the location, load the Mechanim idle animation.
    - Pause for a few seconds.
    - Pick another target location.
    - If the player is within line of sight, head in that direction.
    - If the player is within 1/2 of the sight distance, load the Mechanim run animation and move at double speed towards him.
    - If within close proximity, play Mechanim attack animation.
    - If player escapes line of sight, pick 6 random locations around the last known position of player and search.
    - Nothing found, resume random wandering.
    - If a food item is in sight, head towards it.
    - If 1/2 distance, run.
    - If within close proximity, play Mechanim eating animation for 10 seconds.
    - If player comes by while eating, ignore player unless attacked.
    - Resume random wandering.

    I really want to understand this tool, but chaining these actions together without something going red in the BT just seems impossible. The examples in the starter kit show how to do EACH of these things, but not how to get them operating together.
    Any help, please?

    Mark

    #38930

    In reply to: AI Troubleshooting


    Sigil
    Keymaster

    OK, let’s see if we can’t setup something you can use for your behavior. From the looks of it you need a patrol, chase, and attack setup. Your first issue is that when the AI loses line of sight it doesn’t know what to do anymore, so lets fix that.

    I’d like you to try a tree out real quick and see if the results work for you, I’m just going to type it out here as it won’t be too large. I’m going to skip the audio and animation for now as well since that can be easily added back in with your parallel setup.

    root
       sequencer
          selector
             expression (expression: targetPlayer != null, returns: evaluate)
             parallel (fail: any, succeed: any, tie breaker: fail)
                detect (repeat: until success, form variable: targetPlayer)
                patrol route (waypoint route: "Your Route", move target variable: waypointTarget)
                   move (move target: waypointTarget)
          selector
             parallel (fail: any, succeed: any, tie breaker: fail)
                sequencer (repeat: until failure)
                   expression (expression: targetPosition = position(targetPlayer), returns: success)
                   detect (form variable: targetPlayer)
                move (move target: targetPlayer)
             parallel (fail: any, succeed: any, tie breaker: fail)
                detect (repeat: until success, form variable: targetPlayer)
                move (move target: targetPosition)

    So just to explain what the tree does real quick:

    1. First I check to see if I already have a target (and skip the patrol if I do)
    2. If I don’t have a target, I patrol until I detect a target (I’ll do this forever)
    3. Once I detect a target, I continually note the position of the target while heading towards it
    4. If at any point I can no longer detect the target, I head to the last position I noted, trying to find it again
    5. If I detect the target, or arrive at the position I last saw it at, I start the tree over

    Let’s get this tree going for you, and then we can build on it, adding in the attack. Let me know how it goes.

Viewing 15 results - 1 through 15 (of 75 total)