Пример #1
0
        /// <summary>
        /// Raycasts and stops at the first hit.
        /// </summary>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <returns></returns>
        public HitResult Raycast(Vector3 from, Vector3 to)
        {
            var result = new HitResult(); //result.Succeded is false by default

            var fullDistance = (to - from).LengthSquared();

            using (var rcb = new BulletSharp.ClosestRayResultCallback(from, to))
            {
                collisionWorld.RayTest(ref from, ref to, rcb);

                if (rcb.CollisionObject == null)
                {
                    return(result);
                }
                result.Succeeded          = true;
                result.Collider           = (PhysicsComponent)rcb.CollisionObject.UserObject;
                result.Normal             = rcb.HitNormalWorld;
                result.Point              = rcb.HitPointWorld;
                result.FullLength         = fullDistance;
                result.NormalizedDistance = -1.0f;
                result.StartPoint         = from;
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Raycasts and stops at the first hit.
        /// </summary>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <returns></returns>
        public HitResult Raycast(Vector3 from, Vector3 to)
        {
            var result = new HitResult(); //result.Succeded is false by default

            using (var rcb = new BulletSharp.ClosestRayResultCallback(from, to))
            {
                collisionWorld.RayTest(ref from, ref to, rcb);

                if (rcb.CollisionObject == null)
                {
                    return(result);
                }
                result.Succeeded = true;
                result.Collider  = (Collider)rcb.CollisionObject.UserObject;
                result.Normal    = rcb.HitNormalWorld;
                result.Point     = rcb.HitPointWorld;
            }

            return(result);
        }