sdActorInterface FindOneActor() { Vector3 center = colliShape.point; float radius = colliShape.radius; if (colliShape.type == ShapeType.eCapsule) { center = colliShape.point + colliShape.dir * colliShape.length * 0.5f; radius = colliShape.length * 0.5f + colliShape.radius; } HeaderProto.ESkillObjType objType = (HeaderProto.ESkillObjType)((int)info["byTargetType"]); List <sdActorInterface> lstActor = sdGameLevel.instance.actorMgr.FindActor(castActor, objType, center, new Vector3(0, 0, 1), 1, 0, radius, true); if (lstActor == null) { return(null); } if (colliShape.type == ShapeType.eCapsule) { sdCapsuleShape actorShape = new sdCapsuleShape(); for (int i = 0; i < lstActor.Count; i++) { sdActorInterface actor = lstActor[i]; if (!actor.IsCanSummonAttack(uniqueID)) { continue; } if (actor.GetComponent <Collider>() != null) { if (actor.GetComponent <Collider>().GetType() == typeof(CharacterController)) { actorShape.SetInfo(actor.GetComponent <Collider>() as CharacterController); if (actorShape.IsIntersect(colliShape)) { return(actor); } } } } } else if (colliShape.type == ShapeType.eSphere) { if (lstActor.Count > 0) { return(lstActor[0]); } } return(null); }
List <sdActorInterface> FindActor() { Vector3 center = colliShape.point; float radius = colliShape.radius; if (colliShape.type == ShapeType.eCapsule) { center = colliShape.point + colliShape.dir * colliShape.length * 0.5f; radius = colliShape.length * 0.5f + colliShape.radius; } HeaderProto.ESkillObjType objType = (HeaderProto.ESkillObjType)info["byTargetType"]; List <sdActorInterface> lstActor = sdGameLevel.instance.actorMgr.FindActor(castActor, objType, center, new Vector3(0, 0, 1), 1, 0, radius, true); if (lstActor == null) { return(null); } if (colliShape.type == ShapeType.eCapsule) { List <sdActorInterface> retActor = new List <sdActorInterface>(); sdCapsuleShape actorShape = new sdCapsuleShape(); for (int i = 0; i < lstActor.Count; i++) { sdActorInterface actor = lstActor[i]; if (actor.GetComponent <Collider>() != null) { if (actor.GetComponent <Collider>().GetType() == typeof(CharacterController)) { actorShape.SetInfo(actor.GetComponent <Collider>() as CharacterController); if (colliShape.IsIntersect(actorShape)) { retActor.Add(actor); } } } } return(retActor); } else if (colliShape.type == ShapeType.eSphere) { return(lstActor); } return(null); //if(Physics.SphereCastAll(point,cc.radius,dir,halfheight*2.0f)) }
public bool IsIntersect(sdCapsuleShape c) { Vector3 Y = c.dir; Vector3 X = dir; Vector3 vBegin = c.point - point; Vector3 vEnd = vBegin + c.dir * c.length; bool bIntersect = IsIntersect(vBegin + point, c.radius); if (bIntersect) { return(true); } bIntersect = IsIntersect(vEnd + point, c.radius); if (bIntersect) { return(true); } float fBeginDot = Vector3.Dot(vBegin, X); float fEndDot = Vector3.Dot(vEnd, X); float maxDis = radius + c.radius; if ((fBeginDot <= -maxDis && fEndDot <= -maxDis) || (fBeginDot >= length + maxDis && fEndDot >= length + maxDis)) { return(false); } float fXYDot = Vector3.Dot(Y, X); if (fXYDot > 0.9999f || fXYDot < -0.9999f) { return(false); } else { Vector3 Z = Vector3.Cross(Y, X); Z.Normalize(); float bDotZ = Vector3.Dot(vBegin, Z); if (Mathf.Abs(bDotZ) > length + maxDis) { return(false); } Y = Vector3.Cross(X, Z); Y.Normalize(); Vector2 begin_yz = new Vector2( Vector3.Dot(vBegin, Y), Vector3.Dot(vBegin, Z)); Vector2 end_yz = new Vector2( Vector3.Dot(vEnd, Y), Vector3.Dot(vEnd, Z)); Vector2 yz_dir = end_yz - begin_yz; float be_length = yz_dir.magnitude; yz_dir.Normalize(); float ZeroDot = Vector2.Dot(-begin_yz, yz_dir); if (ZeroDot <= 0) { return(false); } else if (ZeroDot >= be_length) { return(false); } else { Vector3 nearPoint = c.point + c.dir * c.length * ZeroDot / be_length; return(IsIntersect(nearPoint, c.radius)); } } }