News Forums RAIN General Discussion and Troubleshooting Issue with aspect size

This topic contains 2 replies, has 2 voices, and was last updated by  Jeyp 6 months, 2 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #39956

    Jeyp
    Participant

    Hello,

    I am a beginner at Rain AI (and Unity in general). I am currently trying to have one of my GameObject detect whether or not there is some ground ahead of it.

    The aspect is properly detected when my object is in the middle of the platform (My platform is stored in the groundFound variable):

    However, it appears that instead of covering the whole object it is attached to, my aspect only covers about a 1x1x1 Cube, which means that my AI stops detecting the platform long before it should :

    Would one of you be able to tell me where my issue is coming from? Here are some screenshot of my AI’s sensors and my platform’s aspect :

    AI’s Sensors

    Platform’s Entity

    Cheers

    #39967

    Sigil
    Keymaster

    You haven’t done anything wrong, this is just a limitation of the default sensor/aspect system. All aspects are simply points in space for detection. This was done on purpose to avoid taxing the physics system with full colliders.

    So the easy solution is to add more aspects. Obviously this only works so well: large objects will cause problems, multiple aspects are annoying, and the increased aspect count will eventually start to tax the sensor system (not sure what this upper limit is).

    The harder solution, but more correct, would be to create a custom sensor that overrides the VisualSensor class, and add colliders to your platform that you can detect:

    using RAIN.Entities.Aspects;
    using RAIN.Perception.Sensors;
    using RAIN.Serialization;
    using UnityEngine;
    [RAINSerializableClass]
    public class PhysicsSensor : VisualSensor
    {
        [RAINSerializableField]
        private LayerMask _physicsMask = -1;
        protected override bool TestVisibility(RAINAspect aAspect, float aSqrRange)
        {
            // Normal aspect test worked, we're done
            if (base.TestVisibility(aAspect, aSqrRange))
                return true;
            // Being a little pedantic about this, but just in case
            Transform tAspectTransform = aAspect.MountPoint;
            if (tAspectTransform == null)
                tAspectTransform = aAspect.Entity.Form.transform;
            // Do a physics check against the aspect, may need to add a mask for this
            Collider[] tColliders = Physics.OverlapSphere(Position, Range, _physicsMask);
            for (int i = 0; i < tColliders.Length; i++)
            {
                // If the collider is a child (or equal to) our aspect, we're good
                if (tColliders[i].transform.IsChildOf(tAspectTransform))
                    return true;
            }
            return false;
        }
    }

    I just quickly threw that together, so there may be issues with it. Biggest problem with it currently is that it can only use range (and can’t limit it to a cone, for things behind you). You could change the physics call to OverlapBox instead, and create a box that is about the same as the sensor cone. There are probably other options as well, not positive.

    #39972

    Jeyp
    Participant

    Thanks a lot Sigil, that did the trick.

    I modified it to use a Raycast instead, which works for what I was trying to do :

    // Do a physics check against the aspect, may need to add a mask for this
            RaycastHit myRaycastHit = new RaycastHit();
            Physics.Linecast(Position, Position + new Vector3(AI.Body.GetComponent<Transform>().forward.x * 0.49f, -0.6f, 0.0f), out myRaycastHit);
            // If the collider is a child (or equal to) our aspect, we're good
            if (myRaycastHit.collider != null && myRaycastHit.collider.transform.IsChildOf(tAspectTransform))
                return true;

    This is now working fine - just another quick question : In my Behaviour Tree, I wanted to have a move command that would turn the object by 180 degrees. The problem is that I couldn’t figure out what to enter in Face target that would allow me to give a location relative to the object instead of to the world.

    Right now I am using a custom script, which works fine, but I was wondering if there was a way to do that using a move command?

    Thanks again !

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

You must be logged in to reply to this topic.