private void CheckIfInCapturePoint(GameObject w, TacticalWaypoint waypoint) { foreach (var capturePoint in capturePointMap.capturePoints) { BoxCollider waypointDataTrigger = capturePoint.Value.waypointDataTrigger; if (waypointDataTrigger.bounds.Contains(w.transform.position)) { switch (waypoint.waypointType) { case TacticalWaypoint.WaypointType.NonePoint: break; case TacticalWaypoint.WaypointType.CoverPoint: capturePoint.Value.coverpointsOnCapturePoint.Add(waypoint); break; case TacticalWaypoint.WaypointType.AmbushPoint: capturePoint.Value.ambushPointsOnCapturePoint.Add(waypoint); break; default: throw new ArgumentOutOfRangeException(); } // return as soon as we find one. if it is on one capture point, it will never be on another point. // no need to check the other points return; } } }
public GameObject FindNearestAmbushPoint(Vector3 fromPosition, Vector3 targetPosition, LaneScript.LaneSide laneSide, TeamSide.TeamEnum whichTeamSide) { GameObject nearestAmbushPoint = null; float distance = Mathf.Infinity; // Go through all the cover points foreach (GameObject w in ambushPoints) { TacticalWaypoint tw = w.GetComponent <TacticalWaypoint>(); // Skip lanes that are not in the same lane as the current lane we are trying to search for if (tw.belongsToLane != laneSide || tw.closerToWhichTeamSide != whichTeamSide) { continue; } Debug.DrawRay(w.transform.position, targetPosition - w.transform.position, Color.blue, 2); // Get the distance to compare if we found one closer than a previous one Vector3 diff = w.transform.position - fromPosition; // We found a closer coverpoint if (diff.magnitude < distance) { // Set the nearest coverpoint to the one that is closest and actually in cover nearestAmbushPoint = w; distance = diff.magnitude; } } Debug.DrawRay(targetPosition, nearestAmbushPoint.transform.position - targetPosition, Color.yellow, 5); return(nearestAmbushPoint); }
private void AssignLane(GameObject waypoint, TacticalWaypoint wTacticalWaypoint) { if (leftLaneCollider.bounds.Contains(waypoint.transform.position)) { wTacticalWaypoint.belongsToLane = LaneScript.LaneSide.LeftLane; } else if (centerLaneCollider.bounds.Contains(waypoint.transform.position)) { wTacticalWaypoint.belongsToLane = LaneScript.LaneSide.CenterLane; } else if (rightLaneCollider.bounds.Contains(waypoint.transform.position)) { wTacticalWaypoint.belongsToLane = LaneScript.LaneSide.RightLane; } }
private void AssignCloserToTeamSide(GameObject waypoint, TacticalWaypoint wTacticalWaypoint) { if (wTacticalWaypoint.closerToWhichTeamSide != TeamSide.TeamEnum.None) { // Don't override the team side. This was manually put in the scene view } else { if (redSideCollider.bounds.Contains(waypoint.transform.position)) { wTacticalWaypoint.closerToWhichTeamSide = TeamSide.TeamEnum.RedTeam; } if (blueSideCollider.bounds.Contains(waypoint.transform.position)) { wTacticalWaypoint.closerToWhichTeamSide = TeamSide.TeamEnum.BlueTeam; } } }
// Use this for initialization void Start() { caputureLayer = LayerMask.NameToLayer("CapturePointLayer"); coverPoints = new List <GameObject>(); ambushPoints = new List <GameObject>(); // Filter the waypoint types GameObject[] waypoints = GameObject.FindGameObjectsWithTag("Waypoint"); foreach (var w in waypoints) { TacticalWaypoint waypoint = w.GetComponent <TacticalWaypoint>(); // Hide the waypoints when it comes time to gameplay w.GetComponent <MeshRenderer>().enabled = false; AssignLane(w, waypoint); AssignCloserToTeamSide(w, waypoint); CheckIfInCapturePoint(w, waypoint); switch (waypoint.waypointType) { case TacticalWaypoint.WaypointType.CoverPoint: { coverPoints.Add(w); break; } case TacticalWaypoint.WaypointType.AmbushPoint: { ambushPoints.Add(w); break; } default: { break; } } } }
public void GoToCapturePoint(CapturePoint.CapturePointId captureId, TacticalWaypoint.WaypointType findWaypointType, bool preferTeamCover = true) { CapturePoint point = capturePointMap.capturePoints[captureId]; targetArea = point.GetComponent <SphereCollider>(); List <TacticalWaypoint> waypointTypeOnCapturePoint = null; switch (findWaypointType) { case TacticalWaypoint.WaypointType.NonePoint: waypointTypeOnCapturePoint = null; break; case TacticalWaypoint.WaypointType.CoverPoint: waypointTypeOnCapturePoint = point.coverpointsOnCapturePoint; break; case TacticalWaypoint.WaypointType.AmbushPoint: waypointTypeOnCapturePoint = point.ambushPointsOnCapturePoint; break; default: waypointTypeOnCapturePoint = null; break; } // If we want to find a cover point, and the capture point has one if (waypointTypeOnCapturePoint != null && waypointTypeOnCapturePoint.Count != 0) { // If we want cover that is closer to the players team side if (preferTeamCover) { // Create a local list of cover points that belong to a team List <TacticalWaypoint> teamWaypointTypes = new List <TacticalWaypoint>(); foreach (var waypointType in waypointTypeOnCapturePoint) { if (waypointType.closerToWhichTeamSide == team.playerTeam) { teamWaypointTypes.Add(waypointType); } } // If we have some team cover points to go to, then pick a random one if (teamWaypointTypes.Count != 0) { //targetTransform = teamWaypointTypes[Random.Range(0, teamWaypointTypes.Count)].transform; TacticalWaypoint tw = teamWaypointTypes[Random.Range(0, teamWaypointTypes.Count)]; targetTransform = tw.transform; targetArea = tw.GetComponent <SphereCollider>(); } else { // If there are no team cover points found, just pick a random one //targetTransform = waypointTypeOnCapturePoint[Random.Range(0, waypointTypeOnCapturePoint.Count)].transform; TacticalWaypoint tw = waypointTypeOnCapturePoint[Random.Range(0, waypointTypeOnCapturePoint.Count)]; targetTransform = tw.transform; targetArea = tw.GetComponent <SphereCollider>(); } } else { // For now go to a random cover point // targetTransform = waypointTypeOnCapturePoint[Random.Range(0, waypointTypeOnCapturePoint.Count)].transform; TacticalWaypoint tw = waypointTypeOnCapturePoint[Random.Range(0, waypointTypeOnCapturePoint.Count)]; targetTransform = tw.transform; targetArea = tw.GetComponent <SphereCollider>(); } } else { // If we dont want to find either a cover point, or an ambush type, then just go to the capture point //targetTransform = capturePointMap.capturePoints[captureId].transform; CapturePoint tw = capturePointMap.capturePoints[captureId]; targetTransform = tw.transform; targetArea = tw.GetComponent <SphereCollider>(); } }