Why is my raycast hitting "itself" ?

Hi,

Here is my code:

        protected override void OnUpdate()
        {
            _collisionWorld = _physics.PhysicsWorld.CollisionWorld;

            Entities.ForEach((ref GroundCollide collide, ref Translation position) =>
            {
                RaycastInput input = new RaycastInput()
                {
                    Start = position.Value,
                    End = position.Value - math.up(),
                    Filter = new CollisionFilter()
                    {
                        BelongsTo = ~0u,
                        CollidesWith = ~0u,
                        GroupIndex = 0
                    }
                };

                RaycastHit hit = new RaycastHit();
                bool haveHit = _collisionWorld.CastRay(input, out hit);
                if (haveHit)
                {
                    var posi = hit.Position;
                    var distance = math.distance(posi, position.Value);
                    LoggerSystem.Log(posi + " << point... origin >> " + position.Value);

                    // if (distance >= 1.01)
                    // {
                    //     collide.IsGrounded = false;
                    // }
                    // else
                    // {
                    //     collide.IsGrounded = true;
                    // }

                    collide.IsGrounded = true;
                }
            });
        }

I want to build a simple “isGrounded” system, but position.Value is always printing the origin of the ray??

eg posi == position.Value;

What is wrong with my code?

It is likely hitting the collider of the character from inside, which an inside hit always returns a “fraction” of 0, meaning the hit occurs at the ray’s start.

Then why is the docu saying this?

Ray intersection starting inside spheres, capsules, box and convex shapes do not report an intersection as the ray leaves the volume.

You are looking at an old version of the doc. The updated doc clarifies this.

Where can i find the updated docs?

In theory if you open up the package manager, and select the proper package, the documentation link should take you to the proper doc of the version you have installed.

It’s also in your library folder in your project.

Thank you for pointing me in the right direction :slight_smile: