bool IsGrounded(CharacterControl control) { if (control.contactPoints != null) { foreach (ContactPoint c in control.contactPoints) { float colliderBottom = (control.transform.position.y + control.boxCollider.center.y) - (control.boxCollider.size.y / 2f); float yDifference = Mathf.Abs(c.point.y - colliderBottom); if (yDifference < 0.01f) { if (Mathf.Abs(control.RIGID_BODY.velocity.y) < 0.001f) { control.animationProgress.Ground = c.otherCollider.transform.root.gameObject; control.animationProgress.LandingPosition = new Vector3( 0f, c.point.y, c.point.z); if (control.SubComponentsDic.ContainsKey(SubComponents.MANUALINPUT)) { TESTING_SPHERE.transform.position = control.animationProgress.LandingPosition; } return(true); } } } } if (control.RIGID_BODY.velocity.y < 0f) { foreach (GameObject o in control.collisionSpheres.BottomSpheres) { Debug.DrawRay(o.transform.position, -Vector3.up * Distance, Color.yellow); RaycastHit hit; if (Physics.Raycast(o.transform.position, -Vector3.up, out hit, Distance)) { if (!control.RagdollParts.Contains(hit.collider) && !Ledge.IsLedgeChecker(hit.collider.gameObject) && !Ledge.IsCharacter(hit.collider.gameObject)) { control.animationProgress.Ground = hit.collider.transform.root.gameObject; control.animationProgress.LandingPosition = new Vector3( 0f, hit.point.y, hit.point.z); if (control.SubComponentsDic.ContainsKey(SubComponents.MANUALINPUT)) { TESTING_SPHERE.transform.position = control.animationProgress.LandingPosition; } return(true); } } } } control.animationProgress.Ground = null; return(false); }
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); } }
private void OnTriggerExit(Collider other) { CheckLedge = other.gameObject.GetComponent <Ledge>(); if (CheckLedge != null) { IsGrabbingLedge = false; //GrabbedLedge = null; } }
private void OnTriggerEnter(Collider other) { CheckLedge = other.gameObject.GetComponent <Ledge>(); if (CheckLedge != null) { IsGrabbingLedge = true; GrabbedLedge = CheckLedge; } }
private void OnTriggerExit(Collider other) { if (!Ledge.IsCharacter(other.gameObject) && !MeleeWeapon.IsWeapon(other.gameObject)) { if (CollidedObjects.Contains(other.gameObject)) { CollidedObjects.Remove(other.gameObject); } } }
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); } } }
bool UpIsBlocked(CharacterControl control) { foreach (GameObject o in control.collisionSpheres.UpSpheres) { Debug.DrawRay(o.transform.position, control.transform.up * 0.3f, Color.yellow); RaycastHit hit; if (Physics.Raycast(o.transform.position, control.transform.up, out hit, 0.125f)) { if (hit.collider.transform.root.gameObject != control.gameObject && !Ledge.IsLedge(hit.collider.gameObject)) { return(true); } } } return(false); }
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); } } } }