Exemple #1
0
        public bool IsTouchingGround(Vector3 pos, out RaycastResults res)
        {
            int iters = 20;

            res = null;
            for (int i = -1; i < iters; i++)
            {
                float   p         = i / (iters - 1.0f);
                float   xDiff     = Mathf.Sin(p * 2 * Mathf.PI);
                float   yDiff     = Mathf.Cos(p * 2 * Mathf.PI);
                Vector3 curOffset = (new Vector3(xDiff, 0, yDiff)).normalized * feetWidth;
                if (i == -1) // start with no offset (-1 is just a dumb hack to do this)
                {
                    curOffset = new Vector3(0, 0, 0);
                }

                if (PhysicsUtils.RayCast(pos + curOffset, new Vector3(0, -1, 0), heightBelowHead + footDepth, out res))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #2
0
        public bool RayCastWithWidth(Vector3 origin, Vector3 direction, float width, float maxMag, out RaycastResults hitResults)
        {
            int iters = 20;

            hitResults = null;
            for (int i = -1; i < iters; i++)
            {
                float   p         = i / (iters - 1.0f);
                float   xDiff     = Mathf.Sin(p * 2 * Mathf.PI);
                float   yDiff     = Mathf.Cos(p * 2 * Mathf.PI);
                Vector3 curOffset = (new Vector3(xDiff, 0, yDiff)).normalized * width;
                if (i == -1) // start with no offset (-1 is just a dumb hack to do this)
                {
                    curOffset = new Vector3(0, 0, 0);
                }

                if (PhysicsUtils.RayCast(origin + curOffset, direction, maxMag, out hitResults))
                {
                    hitResults.hitPos -= curOffset;
                    return(true);
                }
            }
            return(false);
        }
Exemple #3
0
        bool IntersectingBody(Vector3 position)
        {
            int iters = 20;

            Vector3 topOfHead    = position + new Vector3(0, heightAboveHead, 0);
            Vector3 bottomOfHead = position - new Vector3(0, heightBelowHead, 0);
            float   height       = Vector3.Distance(topOfHead, bottomOfHead);

            for (int i = -1; i < iters; i++)
            {
                float   p         = i / (iters - 1.0f);
                float   xDiff     = Mathf.Sin(p * 2 * Mathf.PI);
                float   yDiff     = Mathf.Cos(p * 2 * Mathf.PI);
                Vector3 curOffset = (new Vector3(xDiff, 0, yDiff)).normalized * feetWidth;
                if (i == -1) // start with no offset (-1 is just a dumb hack to do this)
                {
                    curOffset = new Vector3(0, 0, 0);
                }

                if (PhysicsUtils.RayCast(topOfHead + curOffset, new Vector3(0, -1, 0), height) || PhysicsUtils.RayCast(bottomOfHead + curOffset, new Vector3(0, 1, 0), height))
                {
                    return(true);
                }
            }
            return(false);

            /*
             * float worldScale = World.mainWorld.worldScale;
             *
             *
             *
             * long eyesX = (long)Mathf.Floor(position.x / worldScale);
             * long eyesY = (long)Mathf.Floor(position.y / worldScale);
             * long eyesZ = (long)Mathf.Floor(position.z / worldScale);
             * long feetX = (long)Mathf.Floor(position.x / worldScale);
             * long feetY = (long)Mathf.Floor((position.y - heightBelowHead * 0.9f) / worldScale);
             * long feetZ = (long)Mathf.Floor(position.z / worldScale);
             * long headX = (long)Mathf.Floor(position.x / worldScale);
             * long headY = (long)Mathf.Floor((position.y + heightAboveHead) / worldScale);
             * long headZ = (long)Mathf.Floor(position.z / worldScale);
             * long bodyX = (long)Mathf.Floor(position.x / worldScale);
             * long bodyY = (long)Mathf.Floor((position.y + heightAboveHead / 2.0f) / worldScale);
             * long bodyZ = (long)Mathf.Floor(position.z / worldScale);
             * int atHead = World.mainWorld[headX, headY, headZ];
             * int atEyes = World.mainWorld[eyesX, eyesY, eyesZ];
             * int atFeet = World.mainWorld[feetX, feetY, feetZ];
             * int atBody = World.mainWorld[bodyX, bodyY, bodyZ];
             * return atHead != 0 || atEyes != 0 || atFeet != 0 || atBody != 0;
             * / *
             * LVector3 eyesPos = LVector3.FromUnityVector3(position);
             * LVector3 feetPos = LVector3.FromUnityVector3(position + new Vector3(0, -heightBelowHead+0.02f, 0));
             * LVector3 topOfHeadPos = LVector3.FromUnityVector3(position + new Vector3(0, heightAboveHead, 0));
             * LVector3 bodyPos = LVector3.FromUnityVector3(position + new Vector3(0, -heightBelowHead / 2.0f, 0));
             * LVector3 middleOfHeadPos = LVector3.FromUnityVector3(position + new Vector3(0, heightAboveHead / 2.0f, 0));
             * int atEyes = World.mainWorld[eyesPos];
             * int atFeet = World.mainWorld[feetPos];
             * int atTopOfHead = World.mainWorld[topOfHeadPos];
             * int atBody = World.mainWorld[bodyPos];
             * int atMiddleOfHead = World.mainWorld[middleOfHeadPos];
             * return (atEyes != 0 || atTopOfHead != 0 || atBody != 0 || atMiddleOfHead != 0);
             */
        }