private void CoverTeammate(RobotControls controls, SubjectiveRobot teammate) { Vector3 reltiveEnemyDir = _closestEnemy.currentPosition - teammate.currentPosition; _MoveVector = reltiveEnemyDir.normalized * 2 + teammate.currentPosition; _canMove = true; }
private void ShootBallOwner(RobotControls controls) { StopMovement(controls); currentTarget = _ballOwner; _ShootVector = TargetPrediction(currentTarget, controls); _canShoot = true; }
/// <summary> /// This method calculates Vector3 where projectile should be launced in order to hit the intended target; /// </summary> private Vector3 TargetPrediction(SubjectiveRobot target, RobotControls controls) { float coolDown = 0.5f; float coolDownVar = coolDown; Vector3 predictionPoint; Vector3 startPoint = target.currentPosition; if (coolDownVar > 0) { coolDown -= Time.deltaTime; return(new Vector3(0, 0, 0)); } else { Vector3 endPoint = target.currentPosition; Vector3 targetMovementVector = endPoint - startPoint; targetSpeed = targetMovementVector.magnitude / coolDown; Vector3 distanceVector = endPoint - controls.myself.currentPosition; float distance = distanceVector.magnitude; float projection = Vector3.Project(targetMovementVector, distanceVector).magnitude; float timeToReach; timeToReach = (float)Math.Sqrt((Math.Pow(distance + projection, 2) + (Math.Pow(targetSpeed, 2) - Math.Pow(projection, 2))) / Math.Pow(projectileSpeed, 2)); predictionPoint = targetMovementVector / (coolDown * timeToReach); return(new Vector3(predictionPoint.x, controls.myself.currentPosition.y, predictionPoint.z)); } }
//Shooting States private void ShootClosestTarget(RobotControls controls) { StopMovement(controls); currentTarget = _closestEnemy; _ShootVector = TargetPrediction(currentTarget, controls); _canShoot = true; }
private void GoFromRobot(RobotControls controls, SubjectiveRobot robot) { Vector3 moveDir = controls.myself.currentPosition - robot.currentPosition; //_MoveVector = moveDir.normalized + controls.myself.currentPosition; _MoveVector = moveDir; _canMove = true; }
//Checks who owns the ball private void CheckBallOwnership(RobotControls controls) { _currentBallPosition = controls.updateBall; _iHaveBall = false; _ballCaptured = false; _ballOwnerUnknown = false; foreach (SubjectiveRobot robot in controls.archiveRobots) { if (robot.team == controls.myself.team) { if (Vector3.Distance(robot.currentPosition, _currentBallPosition) < 1.3f) { _ballCaptured = true; _ballOwner = robot; _enemyTeamHasTheBall = false; if (robot.id == controls.myself.id) { Debug.Log("I Have the ball"); _iHaveBall = true; } else { Debug.Log($"My teammate, {_ballOwner} has the ball"); _iHaveBall = false; } } } else { if (robot.isSeen) { if (Vector3.Distance(robot.currentPosition, _currentBallPosition) < 1.3f) { _ballCaptured = true; _ballOwner = robot; _enemyTeamHasTheBall = true; Debug.Log($"My enemy, {_ballOwner} has the ball"); } } else { if (_currentBallPosition != _lastBallPosition) { _ballCaptured = true; _enemyTeamHasTheBall = true; _ballOwnerUnknown = true; Debug.Log($"Unknown enemy has the ball"); } } } } _lastBallPosition = _currentBallPosition; }
private void GoForRobot(RobotControls controls, SubjectiveRobot robot) { _MoveVector = robot.currentPosition; _canMove = true; }
void Attack(SubjectiveRobot target, RobotControls controls) { controls.attack(target.currentPosition); }