private void DoAvoidance(AI ai, RAINAspect aspect) { between = ai.Kinematic.Position - aspect.Position; avoidVector = Vector3.Cross(Vector3.up, between); Vector3 avoidPoint; int direction = Random.Range(0, 100); avoidVector.Normalize(); if(direction < 50) avoidVector *= -1; avoidPoint = GetPositionOnNavMesh(avoidVector, ai); if(avoidPoint == Vector3.zero) { avoidVector *= -1; avoidPoint = GetPositionOnNavMesh(avoidVector, ai); } if(avoidPoint == Vector3.zero) { Debug.Log("Avoid not possible!"); // Change destination ai.WorkingMemory.SetItem("hasArrived", true); return; } ai.Motor.MoveTo(ai.Kinematic.Position + avoidPoint); Debug.Log (ai.Body.name + " is avoiding " + aspect.Entity.Form.name); }
protected override bool TestVisibility(RAINAspect aAspect, float aSqrRange) { // Normal aspect test worked, we're done if (base.TestVisibility(aAspect, aSqrRange)) { return(true); } // Being a little pedantic about this, but just in case Transform tAspectTransform = aAspect.MountPoint; if (tAspectTransform == null) { tAspectTransform = aAspect.Entity.Form.transform; } float sizeX = AI.Body.GetComponent <Renderer>().bounds.size.x; float sizeY = AI.Body.GetComponent <Renderer>().bounds.size.y + 0.1f; float direction = AI.WorkingMemory.GetItem <float>("direction"); // Do a physics check against the aspect, may need to add a mask for this RaycastHit2D myRaycastHit = Physics2D.Linecast(AI.Body.transform.position + new Vector3(direction * sizeX, 0.0f, 0.0f), AI.Body.transform.position + new Vector3(direction * (sizeX + rayRange), 0.0f, 0.0f)); // If the collider is a child (or equal to) our aspect, we're good if (myRaycastHit.collider != null && myRaycastHit.collider.transform.IsChildOf(tAspectTransform)) { return(true); } return(false); }
protected override bool TestVisibility(RAINAspect aAspect, float aSqrRange) { // Normal aspect test worked, we're done if (base.TestVisibility(aAspect, aSqrRange)) return true; // Being a little pedantic about this, but just in case Transform tAspectTransform = aAspect.MountPoint; if (tAspectTransform == null) tAspectTransform = aAspect.Entity.Form.transform; float sizeX = AI.Body.GetComponent<Renderer>().bounds.size.x; float sizeY = AI.Body.GetComponent<Renderer>().bounds.size.y + 0.1f; float direction = AI.WorkingMemory.GetItem<float>("direction"); // Do a physics check against the aspect, may need to add a mask for this RaycastHit2D myRaycastHit = Physics2D.Linecast(AI.Body.transform.position + new Vector3(direction * sizeX,0.0f,0.0f), AI.Body.transform.position + new Vector3(direction * (sizeX + rayRange), 0.0f, 0.0f)); // If the collider is a child (or equal to) our aspect, we're good if (myRaycastHit.collider != null && myRaycastHit.collider.transform.IsChildOf(tAspectTransform)) return true; return false; }
protected override bool TestVisibility(RAINAspect aAspect, float aSqrRange) { // Normal aspect test worked, we're done if (base.TestVisibility(aAspect, aSqrRange)) { return(true); } // Being a little pedantic about this, but just in case Transform tAspectTransform = aAspect.MountPoint; if (tAspectTransform == null) { tAspectTransform = aAspect.Entity.Form.transform; } // Do a physics check against the aspect, may need to add a mask for this RaycastHit myRaycastHit = new RaycastHit(); Physics.Linecast(Position, Position + new Vector3(AI.Body.GetComponent <Transform>().forward.x * 0.49f, -0.6f, 0.0f), out myRaycastHit); // If the collider is a child (or equal to) our aspect, we're good if (myRaycastHit.collider != null && myRaycastHit.collider.transform.IsChildOf(tAspectTransform)) { return(true); } return(false); }
private void doAvoidance(AI ai, RAINAspect aspect) { var direction = ai.Kinematic.Position - aspect.Position; direction.Normalize(); ai.Motor.MoveTo(ai.Kinematic.Position + direction); }
private void DoAvoidance(AI ai, RAINAspect aspect) { between = ai.Kinematic.Position - aspect.Position; avoidVector = Vector3.Cross(Vector3.up, between); int direction = Random.Range(0, 100); avoidVector.Normalize(); if (direction < 50) avoidVector *= -1; if (!CheckPositionOnNavMesh(avoidVector, ai)) avoidVector *= -1; if (!CheckPositionOnNavMesh(avoidVector, ai)) { //Debug.Log("Avoid not possible!"); return; } Vector3 destination = ai.Kinematic.Position + avoidVector; //ai.Motor.MoveTo(destination); //ai.Kinematic.Position += avoidVector; ai.Kinematic.Position = Vector3.Lerp(ai.Kinematic.Position, destination, 0.3f); ai.Motor.FaceAt(avoidVector); }
public override ActionResult Execute(RAIN.Core.AI ai) { if (!AspectVariable.IsVariable) { throw new Exception("The Get Stand On Point node requires a valid AspectVariable."); } if (!StandOnPointVariable.IsVariable) { throw new Exception("The Get Stand On Point node requires a valid StandOnPointVariable."); } RAINAspect tAspect = ai.WorkingMemory.GetItem <RAINAspect>(AspectVariable.VariableName); if (tAspect == null) { return(ActionResult.FAILURE); } Entity tEntity = tAspect.Entity; RAINAspect tStandOnAspect = tEntity.GetAspect("standhere"); if (tStandOnAspect == null) { return(ActionResult.FAILURE); } ai.WorkingMemory.SetItem <RAINAspect>(StandOnPointVariable.VariableName, tStandOnAspect); return(ActionResult.SUCCESS); }
private void DoAvoidance(AI ai, RAINAspect aspect) { between = ai.Kinematic.Position - aspect.Position; avoidVector = Vector3.Cross(Vector3.up, between); int direction = Random.Range(0, 100); avoidVector.Normalize(); if (direction < 50) { avoidVector *= -1; } if (!CheckPositionOnNavMesh(avoidVector, ai)) { avoidVector *= -1; } if (!CheckPositionOnNavMesh(avoidVector, ai)) { //Debug.Log("Avoid not possible!"); return; } Vector3 destination = ai.Kinematic.Position + avoidVector; //ai.Motor.MoveTo(destination); //ai.Kinematic.Position += avoidVector; ai.Kinematic.Position = Vector3.Lerp(ai.Kinematic.Position, destination, 0.3f); ai.Motor.FaceAt(avoidVector); }
private bool isToClose(AI ai, RAINAspect aspect) { var dist = Vector3.Distance(ai.Kinematic.Position, aspect.Position); if (dist <= MINIMUM_DISTANCE) { return(true); } return(false); }
private bool IsTooClose(AI ai, RAINAspect aspect) { float dist = Vector3.Distance(ai.Kinematic.Position, aspect.Position); if (dist <= range) { return(true); } return(false); }
protected override bool TestVisibility(RAINAspect aAspect, float aSqrRange) { // Normal aspect test worked, we're done if (base.TestVisibility(aAspect, aSqrRange)) { return(true); } // Being a little pedantic about this, but just in case Transform tAspectTransform = aAspect.MountPoint; if (tAspectTransform == null) { tAspectTransform = aAspect.Entity.Form.transform; } float sizeX = AI.Body.GetComponent <Renderer>().bounds.size.x / 2; float sizeY = AI.Body.GetComponent <Renderer>().bounds.size.y / 2 + 0.1f; //sizeX *= 1.2f; //sizeY *= 1.2f; if (AI.Body.name.Length >= 15 && AI.Body.name.Substring(0, 15) == "Enemy - Charger") { sizeX *= 0.7f; } float direction = AI.WorkingMemory.GetItem <float>("direction"); // Do a physics check against the aspect, may need to add a mask for this RaycastHit2D myRaycastHit; if (AI.Body.name.Length >= 14 && AI.Body.name.Substring(0, 14) == "Enemy - Flying") { Vector3 from = AI.Body.transform.position + new Vector3(direction * sizeX, 0.0f, 0.0f); Vector3 to = AI.Body.transform.position + new Vector3(direction * sizeX * 1.6f, 0.0f, 0.0f); myRaycastHit = Physics2D.Linecast(from, to); } else { myRaycastHit = Physics2D.Linecast(AI.Body.transform.position + new Vector3(direction * sizeX, -0.01f, 0.0f), AI.Body.transform.position + new Vector3(direction * sizeX, -sizeY, 0.0f)); Debug.DrawLine(AI.Body.transform.position + new Vector3(direction * sizeX, 0.0f, 0.0f), AI.Body.transform.position + new Vector3(direction * sizeX, -sizeY, 0.0f)); } // If the collider is a child (or equal to) our aspect, we're good if (myRaycastHit.collider != null && myRaycastHit.collider.transform.IsChildOf(tAspectTransform)) { return(true); } return(false); }
public ActionResult Execute(RAIN.Core.AI ai) { civil = ai.WorkingMemory.GetItem <RAINAspect>("moveTarget"); //get the list of nav target of the IA state = civil.MountPoint.gameObject.GetComponent <Civilian>().GetState(); if (state == EnumState.EStates.Panic.ToString()) { ai.WorkingMemory.SetItem <bool>("targetPanic", true); ai.Motor.CloseEnoughDistance = 1; } else { ai.WorkingMemory.SetItem <bool>("targetPanic", false); } return(ActionResult.SUCCESS); }
protected override bool TestVisibility(RAINAspect aAspect, float aSqrRange) { // Normal aspect test worked, we're done if (base.TestVisibility(aAspect, aSqrRange)) return true; // Being a little pedantic about this, but just in case Transform tAspectTransform = aAspect.MountPoint; if (tAspectTransform == null) tAspectTransform = aAspect.Entity.Form.transform; // Do a physics check against the aspect, may need to add a mask for this RaycastHit myRaycastHit = new RaycastHit(); Physics.Linecast(Position, Position + new Vector3(AI.Body.GetComponent<Transform>().forward.x * 0.49f, -0.6f, 0.0f), out myRaycastHit); // If the collider is a child (or equal to) our aspect, we're good if (myRaycastHit.collider != null && myRaycastHit.collider.transform.IsChildOf(tAspectTransform)) return true; return false; }
public override ActionResult Execute(RAIN.Core.AI ai) { civil = ai.WorkingMemory.GetItem <RAINAspect>("moveTarget"); //get the list of nav target of the IA if (civil != null) { state = civil.MountPoint.gameObject.GetComponent <Civilian>().GetState(); if (state == EnumState.EStates.Panic.ToString() || state == EnumState.EStates.Run.ToString()) { ai.WorkingMemory.SetItem <bool>("targetPanic", true); } else { ai.WorkingMemory.SetItem <bool>("targetPanic", false); } } else { ai.WorkingMemory.SetItem <bool>("targetPanic", false); } return(ActionResult.SUCCESS); }
protected override bool TestVisibility(RAINAspect aAspect, float aSqrRange) { // Normal aspect test worked, we're done if (base.TestVisibility(aAspect, aSqrRange)) return true; // Being a little pedantic about this, but just in case Transform tAspectTransform = aAspect.MountPoint; if (tAspectTransform == null) tAspectTransform = aAspect.Entity.Form.transform; float sizeX = AI.Body.GetComponent<Renderer>().bounds.size.x/2; float sizeY = AI.Body.GetComponent<Renderer>().bounds.size.y/2 + 0.1f; //sizeX *= 1.2f; //sizeY *= 1.2f; if (AI.Body.name.Length >= 15 && AI.Body.name.Substring(0, 15) == "Enemy - Charger") sizeX *= 0.7f; float direction = AI.WorkingMemory.GetItem<float>("direction"); // Do a physics check against the aspect, may need to add a mask for this RaycastHit2D myRaycastHit; if (AI.Body.name.Length >= 14 && AI.Body.name.Substring(0, 14) == "Enemy - Flying") { Vector3 from = AI.Body.transform.position + new Vector3(direction * sizeX, 0.0f, 0.0f); Vector3 to = AI.Body.transform.position + new Vector3(direction * sizeX * 1.6f, 0.0f, 0.0f); myRaycastHit = Physics2D.Linecast(from, to); } else { myRaycastHit = Physics2D.Linecast(AI.Body.transform.position + new Vector3(direction * sizeX, -0.01f, 0.0f), AI.Body.transform.position + new Vector3(direction * sizeX, -sizeY, 0.0f)); Debug.DrawLine(AI.Body.transform.position + new Vector3(direction * sizeX, 0.0f, 0.0f), AI.Body.transform.position + new Vector3(direction * sizeX, -sizeY, 0.0f)); } // If the collider is a child (or equal to) our aspect, we're good if (myRaycastHit.collider != null && myRaycastHit.collider.transform.IsChildOf(tAspectTransform)) return true; return false; }
private void DoAvoidance(AI ai, RAINAspect aspect) { between = ai.Kinematic.Position - aspect.Position; avoidVector = Vector3.Cross(Vector3.up, between); Vector3 avoidPoint; int direction = Random.Range(0, 100); avoidVector.Normalize(); if (direction < 50) { avoidVector *= -1; } avoidPoint = GetPositionOnNavMesh(avoidVector, ai); if (avoidPoint == Vector3.zero) { avoidVector *= -1; avoidPoint = GetPositionOnNavMesh(avoidVector, ai); } if (avoidPoint == Vector3.zero) { Debug.Log("Avoid not possible!"); // Change destination ai.WorkingMemory.SetItem("hasArrived", true); return; } ai.Motor.MoveTo(ai.Kinematic.Position + avoidPoint); Debug.Log(ai.Body.name + " is avoiding " + aspect.Entity.Form.name); }
private void FindBestCoverPoint(AI ai) { if (!StoreCoverVarInName.IsValid || !StoreCoverVarInName.IsVariable) { return; } //We don't actually have to have an enemy. We can choose cover points that are simply near ourselves. Vector3 tEnemyPosition = ai.Kinematic.Position; //Assign a current enemy target if (EnemyVariable.IsValid && EnemyVariable.IsVariable) { //using a MoveLookTarget lets us automatically convert between gameObject, Vector3, etc., when getting //a position from AI memory tTarget = MoveLookTarget.GetTargetFromVariable(ai.WorkingMemory, EnemyVariable.VariableName, ai.Motor.CloseEnoughDistance); if (tTarget.IsValid) { tEnemyPosition = tTarget.Position; } } //Cover points should be marked with the "cover" entity for (int i = 0; i <= ai.Senses.Sensors.Count; i++) { if (ai.Senses.Sensors [i].SensorName == CoverDetector.VariableName) { CoverSensor = ai.Senses.Sensors [i] as VisualSensor; break; } } CoverSensor.Sense(CoverEntityName.VariableName, RAINSensor.MatchType.ALL); Vector3 previousCoverAspect = ai.Kinematic.Position;; //Default cover point is our own position float bestCost = float.MaxValue; Vector3 tCoverPosition = ai.Kinematic.Position; //return the closest position out of all found positions //that the player cannot see. for (int i = 0; i < CoverSensor.Matches.Count; i++) { //if your current enemy can see the cover position skip it. //This makes the AI choose a more defensable position. Vector3 ray = (tTarget.Position + adjustment); Vector3 direction = (CoverSensor.Matches[i].Position - (tTarget.Position + adjustment)); RaycastHit hit; if (Physics.Raycast(ray, direction, out hit, 100.0f)) { if (hit.collider.transform.gameObject.GetComponent <CoverSpot> ()) { if (hit.collider.transform.gameObject == CoverSensor.Matches [i].MountPoint.gameObject) { continue; } } } //find all cover matches RAINAspect tCandidateAspect = CoverSensor.Matches[i]; if (tCandidateAspect == null) { continue; } //Cover points are AIObjectives, which are objects that allow AI to "occupy" them CoverSpot tObjective = tCandidateAspect.Entity.Form.GetComponent <CoverSpot>(); //Skip occupied cover points if ((tObjective != null) && (tObjective.isTaken) && (tObjective.occupant == ai.Body)) { previousCoverSpot = tObjective; previousCoverAspect = tCandidateAspect.Position; continue; } if ((tObjective == null) || (tObjective.isTaken && tObjective.occupant != ai.Body)) { continue; } //Our cost function gives 50% more weight to points near the enemy //But then also adds in the AI distance to the point float tCost = 1.5f * Vector3.Distance(tEnemyPosition, tCandidateAspect.Position) + Vector3.Distance(ai.Kinematic.Position, tCandidateAspect.Position); if (tCost < bestCost) { currentCoverPoint = tObjective; tCoverPosition = tCandidateAspect.Position; bestCost = tCost; } } //If we found a cover point, then occupy it if (currentCoverPoint != null) { if (previousCoverSpot != null) { previousCoverSpot.LeaveSpot(ai.Body); } currentCoverPoint.TakeSpot(ai.Body); } else if (previousCoverSpot != null) { tCoverPosition = previousCoverAspect; previousCoverSpot.TakeSpot(ai.Body); } //Set the cover position in AI memory ai.WorkingMemory.SetItem <Vector3>(StoreCoverVarInName.VariableName, tCoverPosition); }
private void Chase(AI ai, RAINAspect aspect) { ai.Motor.MoveTo(aspect.Position); }
private bool IsTooClose(AI ai, RAINAspect aspect) { float dist = Vector3.Distance(ai.Kinematic.Position, aspect.Position); if(dist <= range) return true; return false; }
// METHODS ----- new void Start() { base.Start(); _weaponTrail = GetComponentInChildren<TrailRenderer>(); _attackPlanePoint = GetComponentInChildren<PlaneSpawner>(); SoundController = GetComponent<RandomSoundPlayer>(); CollectRadius += 1; // TESTING AddEffectToWeapons(new Damage(25)); ui = GameObject.Find("UI").GetComponent<SpiritMeterUI>(); if (DashEnabled) { _dashTrail = GetComponent<TrailRenderer> (); } _mainCamera = GameObject.FindGameObjectWithTag("MainCamera").camera; _reviveHeartPrefab = (GameObject) Resources.Load("ReviveHeart"); //currentSpiritPower = gameObject.AddComponent<SpiritBungie>(); //currentSpiritPower = gameObject.AddComponent<SpiritLightning>(); //currentSpiritPower = gameObject.AddComponent<SpiritPingPong>(); //currentSpiritPower = gameObject.AddComponent<SpiritImmortal>(); currentSpiritPower = gameObject.AddComponent<SpiritBungie>(); aspect = GetComponentInChildren<EntityRig>().Entity.GetAspect("twinhero"); //Search for menu settings GameObject levelInfo = GameObject.Find("LevelCreationInfo"); if (levelInfo != null) { spiritRegen = levelInfo.GetComponent<LevelCreationInfo>().spiritRegen; _damageRecievedModifier = levelInfo.GetComponent<LevelCreationInfo>().DamageRecievedModifier; } }