override public void Execute() { targetVelocity = StaticMovementAlgorithms.KinematicArrive(selfBody, nextNode.transform.position, ELECTRIC_SPEED, ARRIVE_RADIUS); /* * if (Controls.getDirection() != Vector3.zero) * { * Debug.Log("Controller decided"); * Debug.DrawLine(nextNode.transform.position, nextNode.getNextNavPoint(Controls.getDirection()).transform.position); * } * else * { * Debug.Log("Velocity Decided"); * Debug.DrawLine(nextNode.transform.position, nextNode.getNextNavPoint(selfBody.velocity).transform.position); * } */ if (targetVelocity == Vector3.zero) { if (nextNode.isEndpoint) { Owner.ActionFsm.ChangeState(new IdleState(Owner, Owner.ActionFsm)); } else { ElectricNavpoint nextNodeCandidate; Vector3 input_direction = Controls.getDirection(); if (input_direction != Vector3.zero && Owner.stamina > 0.0f) { nextNodeCandidate = nextNode.getNextNavPoint(input_direction, previousNode); if (nextNodeCandidate == previousNode) { nextNodeCandidate = nextNode.getNextNavPoint(selfBody.velocity, previousNode); } } else { nextNodeCandidate = nextNode.getNextNavPoint(selfBody.velocity, previousNode); } previousNode = nextNode; nextNode = nextNodeCandidate; //Now we trigger any associated devices previousNode.Trigger(); } } Owner.UseStamina(STAMINA_COST_PER_SECOND * Time.deltaTime); }
override public void Execute() { Vector3 arriveVelocity = StaticMovementAlgorithms.KinematicArrive(selfBody, target.transform.position, SPEED, ARRIVE_RADIUS); Vector3 avoidanceVelocity = CollisionPrediction.AvoidCollisions(Owner.gameObject, AVOID_DETECTION_RADIUS, AVOID_MARGIN, SPEED, LayerMask.GetMask("Obstacle"), selfColliders); if (avoidanceVelocity != Vector3.zero) { targetVelocity = 0.6f * arriveVelocity + 0.4f * avoidanceVelocity; } else { targetVelocity = arriveVelocity; } targetVelocity.y = 0.0f; targetVelocity = targetVelocity.normalized * SPEED; }
override public void Execute() { targetVelocity = StaticMovementAlgorithms.KinematicArrive(selfBody, nextNode.transform.position, ELECTRIC_SPEED, ARRIVE_RADIUS); /* * if (Controls.getDirection() != Vector3.zero) * { * Debug.Log("Controller decided"); * Debug.DrawLine(nextNode.transform.position, nextNode.getNextNavPoint(Controls.getDirection()).transform.position); * } * else * { * Debug.Log("Velocity Decided"); * Debug.DrawLine(nextNode.transform.position, nextNode.getNextNavPoint(selfBody.velocity).transform.position); * } */ if (targetVelocity == Vector3.zero) { if (nextNode.isEndpoint) { Owner.ActionFsm.ChangeState(new IdleState(Owner, Owner.ActionFsm)); } else { ElectricNavpoint nextNodeCandidate; Vector3 input_direction = Controls.getDirection(); if (input_direction != Vector3.zero) { nextNodeCandidate = nextNode.getNextNavPoint(input_direction); if (nextNodeCandidate == previousNode) { nextNodeCandidate = nextNode.getNextNavPoint(selfBody.velocity); } } else { nextNodeCandidate = nextNode.getNextNavPoint(selfBody.velocity); } previousNode = nextNode; nextNode = nextNodeCandidate; } } }
override public void Execute() { Vector3 targetDest; //if(Path.Count - PathIndex >= 3) //{ // targetDest = 0.7f * Path[PathIndex].transform.position // + 0.2f * Path[PathIndex + 1].transform.position // + 0.1f * Path[PathIndex + 2].transform.position; //} //else if (Path.Count - PathIndex >= 2) //{ // targetDest = 0.8f * Path[PathIndex].transform.position // + 0.2f * Path[PathIndex + 1].transform.position; //} //else if (Path.Count - PathIndex >= 1) //{ // targetDest = Path[PathIndex].transform.position; //} //else //{ // targetDest = currentTarget.transform.position; //} targetDest = currentTarget.transform.position; Debug.DrawLine(targetDest, targetDest + Vector3.up * 1.0f, Color.red); Vector3 arriveVelocity = StaticMovementAlgorithms.KinematicArrive(selfBody, targetDest, 1.0f, ARRIVE_RADIUS); //Vector3 avoidanceVelocity = // CollisionPrediction.AvoidCollisionsHelper(Owner.gameObject, // AVOID_DETECTION_RADIUS, // 1.5f * Owner.BodyBounds.extents.magnitude, // LayerMask.GetMask("Obstacle"), // selfColliders); Vector3 avoidanceVelocity = CollisionPrediction.AvoidCollisions(Owner.gameObject, AVOID_DETECTION_RADIUS, AVOID_MARGIN, SPEED, LayerMask.GetMask("Obstacle"), selfColliders); avoidanceVelocity.y = 0.0f; if (avoidanceVelocity != Vector3.zero) { targetVelocity = 0.6f * arriveVelocity + 0.4f * avoidanceVelocity; } else { targetVelocity = arriveVelocity; } //targetVelocity.y = 0.0f; targetVelocity = targetVelocity.normalized * Owner.speed; //targetVelocity.y = 0.0f; //float avoidanceSpeed = avoidanceVelocity.magnitude; //avoidanceVelocity.y = 0.0f; //avoidanceVelocity = avoidanceVelocity.normalized * avoidanceSpeed; //targetVelocity = arriveVelocity + avoidanceVelocity; //if (targetVelocity.sqrMagnitude > 1.0f) //{ // targetVelocity = targetVelocity.normalized; //} //targetVelocity *= SPEED; //Debug.Log("chosen target velocity: " + targetVelocity); if (Vector3.Distance(Owner.transform.position, currentTarget.transform.position) < ARRIVE_RADIUS) { //invariant that the path has a unique set of targets PathIndex++; if (PathIndex < Path.Count) { currentTarget = Path[PathIndex]; } } }
override public void Execute() { Vector3 selfPos = Owner.transform.position; Vector3 targetPos = target.transform.position; if (Vector3.Distance(targetPos, selfPos) < ARRIVE_RADIUS) { targetVelocity = Vector3.zero; return; } Vector3 arrivePoint; if (path == null) { if (Mathf.Abs(selfPos.y - targetPos.y) < 0.1f && !Physics.Linecast(selfPos, targetPos, LayerMask.GetMask("Obstacle"))) { // If we're on the same y-plane, and the target is visible // Just target the enemy arrivePoint = targetPos; targetLastPosition = targetPos; } else { // Otherwise, find a path. GeneratePathToTarget(); arrivePoint = pathPointTarget; } } else { // If the target has moved significantly, create a new path. if (Vector3.Distance(targetLastPosition, targetPos) > REPATH_THRESHOLD) { if (repathWait <= 0) { GeneratePathToTarget(); repathWait = Random.Range(0, REPATH_WAIT_MAX); } else { repathWait -= 1; } } // Otherwise, keep following our current path. else { // If we've reached our path way point, get the next if it exists if (Vector3.Distance(selfPos, pathPointTarget) < ARRIVE_RADIUS) { pathIndex++; if (pathIndex < path.Count) { pathPointTarget = path[pathIndex]; } else { path = null; pathPointTarget = targetPos; } } } arrivePoint = pathPointTarget; } Debug.DrawLine(arrivePoint, arrivePoint + Vector3.up * 1.0f, Color.red); Vector3 arriveVelocity = StaticMovementAlgorithms.KinematicArrive(selfBody, arrivePoint, 1.0f, ARRIVE_RADIUS); Vector3 avoidanceVelocity = CollisionPrediction.AvoidCollisionsHelper(Owner.gameObject, AVOID_DETECTION_RADIUS, AVOID_MARGIN, LayerMask.GetMask("Obstacle"), selfColliders); avoidanceVelocity.y = 0.0f; if (avoidanceVelocity != Vector3.zero) { targetVelocity = targetVelocity + avoidanceVelocity * Owner.speed; if (targetVelocity.sqrMagnitude > Owner.speed * Owner.speed) { targetVelocity = targetVelocity.normalized * Owner.speed; } } else { targetVelocity = Vector3.Lerp(targetVelocity, arriveVelocity * Owner.speed, 0.2f); } if (Owner.gameObject == UnityEditor.Selection.activeGameObject) { Debug.Log(Owner.name + " has target vel " + targetVelocity + " arrive vel: " + arriveVelocity + " avoid vel : " + avoidanceVelocity); } }