예제 #1
0
        public static GameObject GetCollidingObject(CharacterControl control, GameObject start, Vector3 dir,
                                                    float blockDistance, ref Vector3 collisionPoint)
        {
            collisionPoint = Vector3.zero;

            //Draw debug line
            Debug.DrawRay(start.transform.position, dir * blockDistance, Color.yellow);

            //Check collision
            RaycastHit hit;

            if (Physics.Raycast(start.transform.position, dir,
                                out hit,
                                blockDistance))
            {
                if (!IsBodyPart(control, hit.collider) &&
                    !IsIgnoringCharacter(control, hit.collider) &&
                    !Ledge.IsLedgeChecker(hit.collider.gameObject) &&
                    !MeleeWeapon.IsWeapon(hit.collider.gameObject) &&
                    !TrapSpikes.IsTrap(hit.collider.gameObject))
                {
                    collisionPoint = hit.point;
                    return(hit.collider.transform.root.gameObject);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
        void CheckRaycastCollision(GameObject obj, Vector3 dir, float blockDistance,
                                   Dictionary <GameObject, GameObject> BlockingObjDic)
        {
            //Draw debug line
            Debug.DrawRay(obj.transform.position, dir * blockDistance, Color.yellow);

            //Check collision
            RaycastHit hit;

            if (Physics.Raycast(obj.transform.position, dir,
                                out hit,
                                blockDistance))
            {
                if (!IsBodyPart(hit.collider) &&
                    !IsIgnoringCharacter(hit.collider) &&
                    !Ledge.IsLedge(hit.collider.gameObject) &&
                    !Ledge.IsLedgeChecker(hit.collider.gameObject) &&
                    !MeleeWeapon.IsWeapon(hit.collider.gameObject) &&
                    !TrapSpikes.IsTrap(hit.collider.gameObject))
                {
                    if (BlockingObjDic.ContainsKey(obj))
                    {
                        BlockingObjDic[obj] = hit.collider.transform.root.gameObject;
                    }
                    else
                    {
                        BlockingObjDic.Add(obj, hit.collider.transform.root.gameObject);
                    }
                }
                else
                {
                    if (BlockingObjDic.ContainsKey(obj))
                    {
                        BlockingObjDic.Remove(obj);
                    }
                }
            }
            else
            {
                if (BlockingObjDic.ContainsKey(obj))
                {
                    BlockingObjDic.Remove(obj);
                }
            }
        }
        void CheckBlockingObjs()
        {
            if (LatestMoveForward.Speed > 0)
            {
                SpheresList = control.collisionSpheres.FrontSpheres;
                DirBlock    = 0.3f;

                foreach (GameObject s in control.collisionSpheres.BackSpheres)
                {
                    if (BlockingObjs.ContainsKey(s))
                    {
                        BlockingObjs.Remove(s);
                    }
                }
            }
            else
            {
                SpheresList = control.collisionSpheres.BackSpheres;
                DirBlock    = -0.3f;

                foreach (GameObject s in control.collisionSpheres.FrontSpheres)
                {
                    if (BlockingObjs.ContainsKey(s))
                    {
                        BlockingObjs.Remove(s);
                    }
                }
            }

            foreach (GameObject o in SpheresList)
            {
                Debug.DrawRay(o.transform.position, control.transform.forward * DirBlock, Color.yellow);
                RaycastHit hit;
                if (Physics.Raycast(o.transform.position, control.transform.forward * DirBlock,
                                    out hit,
                                    LatestMoveForward.BlockDistance))
                {
                    if (!IsBodyPart(hit.collider) &&
                        !IsIgnoringCharacter(hit.collider) &&
                        !Ledge.IsLedge(hit.collider.gameObject) &&
                        !Ledge.IsLedgeChecker(hit.collider.gameObject) &&
                        !MeleeWeapon.IsWeapon(hit.collider.gameObject) &&
                        !TrapSpikes.IsTrap(hit.collider.gameObject))
                    {
                        if (BlockingObjs.ContainsKey(o))
                        {
                            BlockingObjs[o] = hit.collider.transform.root.gameObject;
                        }
                        else
                        {
                            BlockingObjs.Add(o, hit.collider.transform.root.gameObject);
                        }
                    }
                    else
                    {
                        if (BlockingObjs.ContainsKey(o))
                        {
                            BlockingObjs.Remove(o);
                        }
                    }
                }
                else
                {
                    if (BlockingObjs.ContainsKey(o))
                    {
                        BlockingObjs.Remove(o);
                    }
                }
            }
        }