private bool FindRealPoint(ref Matrix transform)
        {
            /* Look for the real height of the step.
             * Move a bit along the ground-collision direction, horizontally,
             * and vertically use 0 and the max step height. */
            Vector3 minTargetPoint = new Vector3(_stepLocal.X, 0, _stepLocal.Z);

            minTargetPoint *= 1 + _stepSearchOvershoot / minTargetPoint.Length;
            // As above: we are using capsule lowest point, rather than ground
            minTargetPoint.Y -= _originHeight;

            Vector3 maxTargetPoint = minTargetPoint;

            maxTargetPoint.Y += _controller.MaxStepHeight + _stepSearchOvershoot;
            minTargetPoint    = Vector3.TransformCoordinate(minTargetPoint, transform);
            maxTargetPoint    = Vector3.TransformCoordinate(maxTargetPoint, transform);

            _closestRay.Setup(ref maxTargetPoint, ref minTargetPoint);
            _world.RayTest(maxTargetPoint, minTargetPoint, _closestRay);
            if (!_closestRay.HasHit)
            {
                return(false);
            }

            if ((1 - _closestRay.ClosestHitFraction) < 0.0001f)
            {
                // Almost at the minimum point, can walk normally
                return(false);
            }

            RealPosWorld = _closestRay.HitPointWorld;
            return(true);
        }
        public Object CastRay(ref Vector3 from, ref Vector3 to, VehicleRaycasterResult result)
        {
            //	RayResultCallback& resultCallback;
            using (ClosestRayResultCallback rayCallback = new ClosestRayResultCallback())
            {
                rayCallback.Setup(ref from, ref to);
                m_dynamicsWorld.RayTestRef(ref from, ref to, rayCallback);

                if (rayCallback.HasHit)
                {
                    RigidBody body = RigidBody.Upcast(rayCallback.CollisionObject);
                    if (body != null && body.HasContactResponse)
                    {
                        result.HitPointInWorld = rayCallback.HitPointWorld;
                        Vector3 hitNormalInWorld = rayCallback.HitNormalWorld;
                        hitNormalInWorld.Normalize();
                        result.HitNormalInWorld = hitNormalInWorld;
                        result.DistFraction     = rayCallback.ClosestHitFraction;
                        return(body);
                    }
                }
            }
            return(null);
        }