public override MoveLookTarget GetNextPathWaypoint(MoveLookTarget aPathTarget, bool aAllow3DMovement, bool aAllowOffGraphMovement, MoveLookTarget aCachedMoveLookTarget = null) { mlt = base.GetNextPathWaypoint(aPathTarget, aAllow3DMovement, aAllowOffGraphMovement, aCachedMoveLookTarget); //Debug.Log("Called GetNextPathWaypoint"); return(mlt); }
public override bool IsAt(MoveLookTarget aPosition) { var fMaxCloseEnoughDistance = Mathf.Max(aPosition.CloseEnoughDistance, AI.Motor.CloseEnoughDistance); bool flag = false; if (AI.Motor.Allow3DMovement) { var vector2 = AI.Kinematic.Position - aPosition.Position; if (vector2.magnitude <= fMaxCloseEnoughDistance) { flag = true; } } else { var position = aPosition.Position; position.y = AI.Kinematic.Position.y; var vector3 = AI.Kinematic.Position - position; if (vector3.magnitude <= fMaxCloseEnoughDistance) { flag = true; } } return(flag); }
public override MoveLookTarget GetNextPathWaypoint(MoveLookTarget aPathTarget, bool aAllow3DMovement, bool aAllowOffGraphMovement, MoveLookTarget aCachedMoveLookTarget = null) { mlt = base.GetNextPathWaypoint(aPathTarget, aAllow3DMovement, aAllowOffGraphMovement, aCachedMoveLookTarget); //Debug.Log("Called GetNextPathWaypoint"); return mlt; }
public override bool IsAt(MoveLookTarget aTarget) { Vector3 tDistance = AI.Body.transform.position - aTarget.Position; tDistance.y = 0; return(tDistance.magnitude <= UnityAgent.stoppingDistance); }
public override ActionResult Execute(RAIN.Core.AI ai) { GameObject loc = ai.WorkingMemory.GetItem<GameObject>("varHero"); MoveLookTarget newTarget = new MoveLookTarget(); newTarget.VectorTarget = new Vector3(loc.transform.position.x, 0, loc.transform.position.z); newTarget.CloseEnoughDistance = ai.Motor.CloseEnoughDistance; ai.WorkingMemory.SetItem(MoveTarget.VariableName, newTarget); return ActionResult.SUCCESS; }
public override ActionResult Execute(RAIN.Core.AI ai) { if (!WanderTargetVariable.IsVariable) { throw new Exception("The Choose Wander Position node requires a valid Wander Target Variable"); } float tWanderDistance = 0f; if (WanderDistance.IsValid) { tWanderDistance = WanderDistance.Evaluate <float>(ai.DeltaTime, ai.WorkingMemory); } if (tWanderDistance <= 0f) { tWanderDistance = _defaultWanderDistance; } MoveLookTarget.GetTargetFromVariable(ai.WorkingMemory, AspectVariable.VariableName, ai.Motor.DefaultCloseEnoughDistance, followTarget); //move in the direction of target Vector3 tAway = ai.Kinematic.Position + followTarget.Position; Vector3 tFollowDirection = tAway.normalized * UnityEngine.Random.Range(1f, tWanderDistance); Vector3 tFollowPosition = ai.Kinematic.Position + tFollowDirection; // if (ai.Navigator.OnGraph(tFollowPosition, ai.Motor.MaxHeightOffset)) // { ai.WorkingMemory.SetItem <Vector3>(WanderTargetVariable.VariableName, tFollowPosition); return(ActionResult.SUCCESS); // } // Vector3 tDirection = followTarget.Position;//new Vector3(UnityEngine.Random.Range(-1f, 1f), 0f, UnityEngine.Random.Range(-1f, 1f)); // // tDirection *= tWanderDistance; // // Vector3 tDestination = ai.Kinematic.Position + tDirection; //// if (StayOnGraph.IsValid && (StayOnGraph.Evaluate<bool>(ai.DeltaTime, ai.WorkingMemory))) //// { //// if (NavigationManager.Instance.GraphForPoint(tDestination, ai.Motor.MaxHeightOffset, NavigationManager.GraphType.Navmesh, ((BasicNavigator)ai.Navigator).GraphTags).Count == 0) //// return ActionResult.FAILURE; //// } // // ai.WorkingMemory.SetItem<Vector3>(WanderTargetVariable.VariableName, tDestination); // // return ActionResult.SUCCESS; }
public override bool IsFacing(MoveLookTarget aTarget) { if (aTarget == null || !aTarget.IsValid) { return(false); } Vector3 tFaceTargetPosition = aTarget.Position; tFaceTargetPosition.y = AI.Body.transform.position.y; Vector3 tDirection = aTarget.Position - AI.Body.transform.position; tDirection.y = 0; return(Mathf.Abs(MathUtils.WrapAngle(Vector3.Angle(AI.Body.transform.forward, tDirection.normalized))) <= CloseEnoughAngle); }
public override ActionResult Execute(AI ai) { //get player GameObject player = ai.WorkingMemory.GetItem<GameObject>("posPlayer"); var playerPosition = player.transform.position; //Debug.Log("p: " + playerPosition); //get enemy position var enemyPosition = new Vector3(ai.Kinematic.Position.x, ai.Kinematic.Position.y, ai.Kinematic.Position.z); //Debug.Log("e: " + enemyPosition); //computes the different between both positions var difference = (enemyPosition - playerPosition); //normalizes the vector //difference.Normalize(); //Debug.Log("dif: " + difference); //checks how close enemy and player are var dist = Vector3.Distance(playerPosition, enemyPosition); var mag = remap(dist, 0, 11, 11, 0); difference *= (mag/3); //Debug.Log("old mag: " + dist + " new mag: " + mag); //computes the new escape point var result = (enemyPosition+difference); //Debug.Log("new scape point: " + result); result.y = playerPosition.y; //update the scapePoint var newPosition = new MoveLookTarget(); //result.VectorTarget = new Vector3(200,1,215); newPosition.VectorTarget = result; ai.WorkingMemory.SetItem<MoveLookTarget>("escapePoint", newPosition); //ai.Motor.MoveTo(result); return ActionResult.SUCCESS; }
public override ActionResult Execute(RAIN.Core.AI ai) { if (!FleeTargetVariable.IsVariable) { throw new Exception("The Choose Flee Position node requires a valid Flee Target Variable"); } float tFleeDistance = 0f; if (FleeDistance.IsValid) { tFleeDistance = FleeDistance.Evaluate <float>(ai.DeltaTime, ai.WorkingMemory); } if (tFleeDistance <= 0f) { tFleeDistance = _defaultFleeDistance; } //Start by trying to flee away from the FleeFrom if (FleeFrom.IsVariable) { MoveLookTarget.GetTargetFromVariable(ai.WorkingMemory, FleeFrom.VariableName, ai.Motor.DefaultCloseEnoughDistance, _fleeTarget); } else { _fleeTarget.TargetType = MoveLookTarget.MoveLookTargetType.None; } if (_fleeTarget.IsValid) { //Start by just running the opposite direction Vector3 tAway = ai.Kinematic.Position - _fleeTarget.Position; Vector3 tFleeDirection = tAway.normalized * UnityEngine.Random.Range(1f, tFleeDistance); Vector3 tFleePosition = ai.Kinematic.Position + tFleeDirection; if (ai.Navigator.OnGraph(tFleePosition, ai.Motor.MaxHeightOffset)) { ai.WorkingMemory.SetItem <Vector3>(FleeTargetVariable.VariableName, tFleePosition); return(ActionResult.SUCCESS); } //Check forty five away Vector3 tFortyFive = Quaternion.Euler(new Vector3(0, 45, 0)) * tFleeDirection; tFleePosition = ai.Kinematic.Position + tFortyFive; if (ai.Navigator.OnGraph(tFleePosition, ai.Motor.MaxHeightOffset)) { ai.WorkingMemory.SetItem <Vector3>(FleeTargetVariable.VariableName, tFleePosition); return(ActionResult.SUCCESS); } //Check minus forty five away tFortyFive = Quaternion.Euler(new Vector3(0, -45, 0)) * tFleeDirection; tFleePosition = ai.Kinematic.Position + tFortyFive; if (ai.Navigator.OnGraph(tFleePosition, ai.Motor.MaxHeightOffset)) { ai.WorkingMemory.SetItem <Vector3>(FleeTargetVariable.VariableName, tFleePosition); return(ActionResult.SUCCESS); } } //We could not find a reasonable flee target, so just choose a random point Vector3 tDirection = new Vector3(UnityEngine.Random.Range(-1f, 1f), 0f, UnityEngine.Random.Range(-1f, 1f)); tDirection *= tFleeDistance; Vector3 tDestination = ai.Kinematic.Position + tDirection; if (StayOnGraph.IsValid && (StayOnGraph.Evaluate <bool>(ai.DeltaTime, ai.WorkingMemory))) { if (!ai.Navigator.OnGraph(tDestination, ai.Motor.MaxHeightOffset)) { return(ActionResult.FAILURE); } } ai.WorkingMemory.SetItem <Vector3>(FleeTargetVariable.VariableName, tDestination); return(ActionResult.SUCCESS); }
public override bool IsFacing(MoveLookTarget aTarget) { // Too tired to do this return(true); }
public override bool IsFacing(MoveLookTarget aTarget) { //TODO return(true); }
public override bool GetPathToMoveTarget(MoveLookTarget aPathTarget, bool allowOffGraphMovement, out RAINPath path) { //Debug.Log("Called GetPathToMoveTarget"); var result = base.GetPathToMoveTarget(aPathTarget, allowOffGraphMovement, out path); for (int i = 0; i < path.PathPoints.Count; i++) { var p = path.PathPoints[i]; path.PathPoints[i] = new Vector3(Mathf.Round(p.x), 0, Mathf.Round(p.z)); } if (path.PathNodes.Count == 2) { return(result); } for (int i = 0; i < path.PathNodes.Count - 1; i++) { if (path.PathPoints[i] == path.PathPoints[i + 1]) { path.RemovePathNode(i); i--; } } bool sameX = false; bool sameZ = false; for (int i = 0; i < path.PathNodes.Count - 1; i++) { //if (Mathf.Approximately(path.PathPoints[i].x, AI.Body.transform.position.x) && // Mathf.Approximately(path.PathPoints[i].z, AI.Body.transform.position.z)) //{ //path.RemovePathNode(i); //i--; //} if (sameX) { if (path.PathPoints[i].x == path.PathPoints[i + 1].x) { path.RemovePathNode(i); i--; } else { sameX = false; } } else if (sameZ) { if (path.PathPoints[i].z == path.PathPoints[i + 1].z) { path.RemovePathNode(i); i--; } else { sameZ = false; } } if (!sameX && !sameZ) { if (path.PathPoints[i].x == path.PathPoints[i + 1].x) { sameX = true; } else if (path.PathPoints[i].z == path.PathPoints[i + 1].z) { sameZ = true; } } } if (Mathf.Approximately(path.PathPoints[0].x, path.PathPoints[path.PathPoints.Count - 1].x) || Mathf.Approximately(path.PathPoints[0].z, path.PathPoints[path.PathPoints.Count - 1].z)) { for (int i = 1; i < path.PathPoints.Count - 1; i++) { path.RemovePathNode(i); --i; } } return(result); }
public override ActionResult Execute(RAIN.Core.AI ai) { if (!FleeTargetVariable.IsVariable) { throw new Exception("The Choose Flee Position node requires a valid Flee Target Variable"); } float _tFleeDistance = 0f; if (FleeDistance.IsValid) { _tFleeDistance = FleeDistance.Evaluate <float>(ai.DeltaTime, ai.WorkingMemory); } if (_tFleeDistance <= 0f) { _tFleeDistance = defaultFleeDistance; } if (FleeFrom.IsVariable) { MoveLookTarget.GetTargetFromVariable(ai.WorkingMemory, FleeFrom.VariableName, ai.Motor.DefaultCloseEnoughDistance, fleeTarget); } else { fleeTarget.TargetType = MoveLookTarget.MoveLookTargetType.None; } if (fleeTarget.IsValid) { Vector3 _tAway = ai.Kinematic.Position - fleeTarget.Position; Vector3 _tFleeDirection = _tAway.normalized * UnityEngine.Random.Range(1f, _tFleeDistance); Vector3 _tFleePosition = ai.Kinematic.Position + _tFleeDirection; if (ai.Navigator.OnGraph(_tFleePosition, ai.Motor.MaxHeightOffset)) { ai.WorkingMemory.SetItem <Vector3>(FleeTargetVariable.VariableName, _tFleePosition); return(ActionResult.SUCCESS); } Vector3 tFortyFive = Quaternion.Euler(new Vector3(0, 45, 0)) * _tFleeDirection; _tFleePosition = ai.Kinematic.Position + tFortyFive; if (ai.Navigator.OnGraph(_tFleePosition, ai.Motor.MaxHeightOffset)) { ai.WorkingMemory.SetItem <Vector3>(FleeTargetVariable.VariableName, _tFleePosition); return(ActionResult.SUCCESS); } tFortyFive = Quaternion.Euler(new Vector3(0, -45, 0)) * _tFleeDirection; _tFleePosition = ai.Kinematic.Position + tFortyFive; if (ai.Navigator.OnGraph(_tFleePosition, ai.Motor.MaxHeightOffset)) { ai.WorkingMemory.SetItem <Vector3>(FleeTargetVariable.VariableName, _tFleePosition); return(ActionResult.SUCCESS); } } Vector3 _tDirection = new Vector3(UnityEngine.Random.Range(-1f, 1f), 0f, UnityEngine.Random.Range(-1f, 1f)); Vector3 _tDestination = ai.Kinematic.Position + _tDirection.normalized * _tFleeDistance; if (StayOnGraph.IsValid && (StayOnGraph.Evaluate <bool>(ai.DeltaTime, ai.WorkingMemory))) { if (!ai.Navigator.OnGraph(_tDestination, ai.Motor.MaxHeightOffset)) { return(ActionResult.FAILURE); } } ai.WorkingMemory.SetItem <Vector3>(FleeTargetVariable.VariableName, _tDestination); return(ActionResult.SUCCESS); }
public override bool IsAt(MoveLookTarget aTarget) { //Debug.Log("Called IsAt"); return(base.IsAt(aTarget)); }
public override bool GetPathToMoveTarget(MoveLookTarget aPathTarget, bool aAllowOffGraphMovement, out RAINPath aPath) { throw new NotImplementedException(); }
public override bool GetPathToMoveTarget(MoveLookTarget aPathTarget, bool allowOffGraphMovement, out RAINPath path) { //Debug.Log("Called GetPathToMoveTarget"); var result = base.GetPathToMoveTarget(aPathTarget, allowOffGraphMovement, out path); for (int i = 0; i < path.PathPoints.Count; i++) { var p = path.PathPoints[i]; path.PathPoints[i] = new Vector3(Mathf.Round(p.x), 0, Mathf.Round(p.z)); } if (path.PathNodes.Count == 2) { return result; } for (int i = 0; i < path.PathNodes.Count - 1; i++) { if (path.PathPoints[i] == path.PathPoints[i + 1]) { path.RemovePathNode(i); i--; } } bool sameX = false; bool sameZ = false; for (int i = 0; i < path.PathNodes.Count - 1; i++) { //if (Mathf.Approximately(path.PathPoints[i].x, AI.Body.transform.position.x) && // Mathf.Approximately(path.PathPoints[i].z, AI.Body.transform.position.z)) //{ //path.RemovePathNode(i); //i--; //} if (sameX) { if (path.PathPoints[i].x == path.PathPoints[i + 1].x) { path.RemovePathNode(i); i--; } else { sameX = false; } } else if (sameZ) { if (path.PathPoints[i].z == path.PathPoints[i + 1].z) { path.RemovePathNode(i); i--; } else { sameZ = false; } } if (!sameX && !sameZ) { if (path.PathPoints[i].x == path.PathPoints[i + 1].x) { sameX = true; } else if (path.PathPoints[i].z == path.PathPoints[i + 1].z) { sameZ = true; } } } if (Mathf.Approximately(path.PathPoints[0].x, path.PathPoints[path.PathPoints.Count - 1].x) || Mathf.Approximately(path.PathPoints[0].z, path.PathPoints[path.PathPoints.Count - 1].z)) { for (int i = 1; i < path.PathPoints.Count - 1; i++) { path.RemovePathNode(i); --i; } } return result; }
public override bool IsAt(MoveLookTarget aTarget) { return IsAt(aTarget.Position); }
public override MoveLookTarget GetNextPathWaypoint(MoveLookTarget aPathTarget, bool aAllow3DMovement, bool aAllowOffGraphMovement, MoveLookTarget aCachedMoveLookTarget = null) { throw new NotImplementedException(); }
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); }
//TODO do I need Reset() implemented also? public override bool IsAt(MoveLookTarget aTarget) { return(IsAt(aTarget.Position)); }
public override MoveLookTarget GetNextPathWaypoint(bool allow3DMovement, bool allowOffGraphMovement, MoveLookTarget moveLookTarget) { if (moveLookTarget == null) { moveLookTarget = new RAIN.Motion.MoveLookTarget(); } if ((base.pathTarget == null) || !base.pathTarget.IsValid) { moveLookTarget.TargetType = MoveLookTarget.MoveLookTargetType.None; return(moveLookTarget); } if (_aStarAIPath.canMove) { _aStarAIPath.TargetPosition = wp.position; moveLookTarget.VectorTarget = _aStarAIPath.TargetPoint; } return(moveLookTarget); }
public override bool IsAt(MoveLookTarget aPosition) { var fMaxCloseEnoughDistance = Mathf.Max(aPosition.CloseEnoughDistance, AI.Motor.CloseEnoughDistance); bool flag = false; if (AI.Motor.Allow3DMovement) { var vector2 = AI.Kinematic.Position - aPosition.Position; if (vector2.magnitude <= fMaxCloseEnoughDistance) { flag = true; } } else { var position = aPosition.Position; position.y = AI.Kinematic.Position.y; var vector3 = AI.Kinematic.Position - position; if (vector3.magnitude <= fMaxCloseEnoughDistance) { flag = true; } } return flag; }
public override bool IsAt(MoveLookTarget aTarget) { //Debug.Log("Called IsAt"); return base.IsAt(aTarget); }
public override MoveLookTarget GetNextPathWaypoint(bool allow3DMovement, bool allowOffGraphMovement, MoveLookTarget moveLookTarget) { if (moveLookTarget == null) { moveLookTarget = new RAIN.Motion.MoveLookTarget(); } if ((base.pathTarget == null) || !base.pathTarget.IsValid) { moveLookTarget.TargetType = MoveLookTarget.MoveLookTargetType.None; return moveLookTarget; } if (_aStarAIPath.canMove) { _aStarAIPath.TargetPosition = wp.position; moveLookTarget.VectorTarget = _aStarAIPath.TargetPoint; } return moveLookTarget; }
public override bool IsFacing(MoveLookTarget aTarget) { // Too tired to do this return true; }