internal static void Run() { try { Console.WriteLine("Pyramid high [foot]: "); var pyramidHigh = double.Parse(Console.ReadLine()); Console.WriteLine("Soccer ball diameter [cm]: "); var soccerBallDiameter = double.Parse(Console.ReadLine()); var soccerBall = new SoccerBall(soccerBallDiameter); var pyramid = PyramidFactory.Build(pyramidHigh, soccerBall); Console.WriteLine("The pyramid was created from {0} soccer balls.", pyramid.NumberOfUsedBalls); } catch (FormatException formatException) { Console.WriteLine(formatException.Message); } finally { Console.WriteLine("Press any key to exit..."); Console.ReadLine(); } }
// Start is called before the first frame update void Start() { if (teamColor == TeamColor.Blue) { opponentsGoal = GameObject.Find("Reds").transform.GetChild(2).GetComponent <Goal>(); homeGoal = GameObject.Find("Blues").transform.GetChild(2).GetComponent <Goal>(); opponentTeam = GameObject.Find("RedTeam").GetComponent <SoccerTeam>(); } else { opponentsGoal = GameObject.Find("Blues").transform.GetChild(2).GetComponent <Goal>(); homeGoal = GameObject.Find("Reds").transform.GetChild(2).GetComponent <Goal>(); opponentTeam = GameObject.Find("BlueTeam").GetComponent <SoccerTeam>(); } //players = new List<GameObject>(); for (int i = 0; i < 5; i++) { // players.Add(gameObject.transform.GetChild(i).gameObject); initialRegion[i] = gameObject.transform.GetChild(i).transform.position; } // Set the FSM m_pStateMachine = new StateMachine <SoccerTeam>(this); m_pStateMachine.SetCurrentState(PrepareForKickOff.instance); // m_pStateMachine.SetGlobalState(MinerGlobalState.instance); ball = GameObject.Find("Ball").GetComponent <SoccerBall>(); //ChangeState(EnterMineAndDigForNugget.instance); StartCoroutine(Updating()); }
public void OnEnter(Entity ent) { if (NetworkManager.IsMasterClient == false) { return; } if (ent.Is <SoccerBall> () == false) { return; } SoccerBall ball = ent.GetComponent <SoccerBall> (); Tank tank = Tank.All.Find(x => x.ID == ball.LastViewToTouch); if (tank != null) { int reward = tank.Team.Number == team ? playerPointsPerGoal : -playerPointsPerGoal / 2; tank.Score += reward; } Server.Current?.IncreaseTeamScore(this.team, this.teamPointsPerGoal); onScore.Invoke(team); }
// 각 팀의 초기설정 지정 void Start() { if (teamColor == TeamColor.Blue) { opponentsGoal = GameObject.Find("Reds").transform.GetChild(2).GetComponent <Goal>(); homeGoal = GameObject.Find("Blues").transform.GetChild(2).GetComponent <Goal>(); opponentTeam = GameObject.Find("RedTeam").GetComponent <SoccerTeam>(); } else { opponentsGoal = GameObject.Find("Blues").transform.GetChild(2).GetComponent <Goal>(); homeGoal = GameObject.Find("Reds").transform.GetChild(2).GetComponent <Goal>(); opponentTeam = GameObject.Find("BlueTeam").GetComponent <SoccerTeam>(); } for (int i = 0; i < 5; i++) { initialRegion[i] = gameObject.transform.GetChild(i).transform.position; } // Set the FSM m_pStateMachine = new StateMachine <SoccerTeam>(this); m_pStateMachine.SetCurrentState(PrepareForKickOff.instance); ball = GameObject.Find("Ball").GetComponent <SoccerBall>(); StartCoroutine(UpdateTeamState()); }
// Use this for initialization void Start() { ball = FindObjectOfType <SoccerBall>(); anim.AddClip(Socc, "Socc"); tra = anim["Socc"]; bal.GetComponent <Animation>()["Socc"].wrapMode = WrapMode.Loop; bal.GetComponent <Animation>().Play("Socc"); }
void Start() { goalCenter = (leftPost.position - rightPost.position) / 2 + rightPost.position; Debug.Log("Goal center z = " + goalCenter.z); goalieRig = GetComponentInChildren <AIRig>(); goalieRig.AI.WorkingMemory.SetItem <Vector3>("GoalCenter", goalCenter); soccerBall = FindObjectOfType <SoccerBall>(); goalieRig.AI.WorkingMemory.SetItem <Vector3>("SoccerBallPos", soccerBall.transform.position); }
void Start() { goalCenter = (leftPost.position - rightPost.position)/2 + rightPost.position; Debug.Log("Goal center z = " + goalCenter.z); goalieRig = GetComponentInChildren<AIRig>(); goalieRig.AI.WorkingMemory.SetItem<Vector3>("GoalCenter", goalCenter); soccerBall = FindObjectOfType<SoccerBall>(); goalieRig.AI.WorkingMemory.SetItem<Vector3>("SoccerBallPos", soccerBall.transform.position); }
void Awake() { canResetBall = true; ballRb = ball.GetComponent <Rigidbody>(); m_BallController = ball.GetComponent <SoccerBall>(); m_BallController.area = this; ballStartingPos = ball.transform.position; m_ResetParams = Academy.Instance.EnvironmentParameters; }
public void OnGetBall(SoccerBall _soccerBall) { soccerBall = _soccerBall; soccerBall.transform.position = parentedSoccerBallTransform.position; soccerBall.transform.rotation = transform.rotation; soccerBall.rigidbody.freezeRotation = true; isPlayerInPossessionOfABall = true; Physics.IgnoreCollision(gameObject.collider, soccerBall.collider); }
void Start() { // Make sure that the controller is controlling a ball. if (m_soccerBall == null) { m_soccerBall = GetComponent <SoccerBall>(); } Assert.IsNotNull(m_soccerBall, "Error! The SoccerBallController has no SoccerBall!"); // Set the initial kick strength to the min. Reset(); }
internal GameManager m_gameManager; // The game manager to notify when a goal has been scored. private void OnTriggerEnter(Collider other) { // While anything can enter the net, only soccer balls can score a goal, // and only if that soccer ball has not already scored a goal in that net since it's last reset. SoccerBall ball = other.gameObject.GetComponent <SoccerBall>(); if (ball != null && ball.CanScore()) { ball.OnScore(); // Notify the ball that it can no longer score until it is reset. m_gameManager.OnScore(); // Notify the game manager that a goal has been scored. } }
/// <inheritdoc /> public void InitializeState(GameMap createdMap) { if (this.PlugInManager is null) { throw new InvalidOperationException("PlugInManager must be set first"); } this.logger.LogDebug("Start creating monster instances for map {createdMap}", createdMap); foreach (var spawn in createdMap.Definition.MonsterSpawns.Where(s => s.SpawnTrigger == SpawnTrigger.Automatic && s.MonsterDefinition is not null)) { for (int i = 0; i < spawn.Quantity; i++) { var monsterDef = spawn.MonsterDefinition !; NonPlayerCharacter npc; var intelligence = this.TryCreateConfiguredNpcIntelligence(monsterDef, createdMap); if (monsterDef.ObjectKind == NpcObjectKind.Monster) { this.logger.LogDebug("Creating monster {spawn}", spawn); npc = new Monster(spawn, monsterDef, createdMap, this.defaultDropGenerator, intelligence ?? new BasicMonsterIntelligence(), this.PlugInManager); } else if (monsterDef.ObjectKind == NpcObjectKind.Trap) { this.logger.LogDebug("Creating trap {spawn}", spawn); npc = new Trap(spawn, monsterDef, createdMap, intelligence ?? new RandomAttackInRangeTrapIntelligence(createdMap)); } else if (monsterDef.ObjectKind == NpcObjectKind.SoccerBall) { this.logger.LogDebug("Creating soccer ball {spawn}", spawn); npc = new SoccerBall(spawn, monsterDef, createdMap); } else { this.logger.LogDebug("Creating npc {spawn}", spawn); npc = new NonPlayerCharacter(spawn, monsterDef, createdMap); } try { npc.Initialize(); createdMap.Add(npc); } catch (Exception ex) { this.logger.LogError(ex, $"Object {spawn} couldn't be initialized.", spawn); npc.Dispose(); } } } this.logger.LogDebug("Finished creating monster instances for map {createdMap}", createdMap); }
// 모든 플레이어가 본래 위치에 있을 경우, 경기 재개 private IEnumerator WaitTillWallPlayerAtHome() { GoalKeeper keeper = GameObject.Find("1").GetComponent <GoalKeeper>(); while (!keeper.Team().AllPlayersAtHome() || !keeper.Team().opponentTeam.AllPlayersAtHome()) { keeper.Team().opponentTeam.ReturnAllFieldPlayersToHome(); keeper.Team().ReturnAllFieldPlayersToHome(); yield return(new WaitForSeconds(0.09f)); } SoccerBall ball = GameObject.Find("Ball").GetComponent <SoccerBall>(); ball.ResetBallState(); }
/// <summary> /// Builds a pyramid from given high and soccer ball(s). /// </summary> /// <param name="pyramidHigh">Pyramid high in [cm].</param> /// <param name="soccerBall">Soccer ball.</param> /// <returns>Builded pyramid.</returns> internal static Pyramid Build(double pyramidHigh, SoccerBall soccerBall) { var pyramid = new Pyramid(pyramidHigh); var pyramidHighInCm = Conversion.FootToCentimeters(pyramid.High); var smallPyramidInsideBallsHigh = Geometrics.CalculateTetrahedronHigh(soccerBall.Diameter); //n = (ph + h - d)/h var numberOfPyramidLevels = Math.Round((pyramidHighInCm + smallPyramidInsideBallsHigh - soccerBall.Diameter) / smallPyramidInsideBallsHigh); pyramid.NumberOfUsedBalls = GetTotalNumberOfBallsUsedInConstruction(numberOfPyramidLevels); return pyramid; }
private void DoAction() { Debug.Log("Completed Action:" + targets[currentIndex].label); if (targets[currentIndex].effect != null) { targets[currentIndex].effect.SetActive(true); } if (currentIndex == 3) { SoccerBall ball = targets[currentIndex].transform.GetComponent <SoccerBall>(); ball.KickBall(); } currentIndex++; }
// Event handling method for the "Fire" button public void FireButtonClicked(object source, EventArgs e) { // Extract input values from textfields double vx0 = Convert.ToDouble(vxTextBox.Text); double vy0 = Convert.ToDouble(vyTextBox.Text); double vz0 = Convert.ToDouble(vzTextBox.Text); double spinRate = Convert.ToDouble(spinRateTextBox.Text); double rx = Convert.ToDouble(rxTextBox.Text); double ry = Convert.ToDouble(ryTextBox.Text); double rz = Convert.ToDouble(rzTextBox.Text); // Calculate the angular velocity from the spin rate. double omega = spinRate * 2.0 * Math.PI; // The ball starts at a spot 18 meters from and directly // in front of the goal. double x0 = 23.2; double y0 = 15.0; double z0 = 0.0; // Set the density to be sea level, the wind // velocity to zero, and temperature to be 294 K. double density = 1.2; double temperature = 294.0; double windVx = 0.0; double windVy = 0.0; // Define some soccer ball variables. The cd value will be // overridden in the getFunction method of the SoccerBall class. double ballMass = 0.43; double radius = 0.11; double area = Math.PI * radius * radius; double cd = 0.25; // Create a SoccerBall object representing the soccer ball. soccerBall = new SoccerBall(x0, y0, z0, vx0, vy0, vz0, 0.0, ballMass, area, density, cd, windVx, windVy, rx, ry, rz, omega, radius, temperature); // Update the display UpdateDisplay(); // Fire the golf ball using a Timer object // to slow down the action. gameTimer.Start(); }
Vector2 Pursuit(SoccerBall ball) { Vector2 toBall = ball.transform.position - player.transform.position; //the lookahead time is proportional to the distance between the ball //and the pursuer; float lookAheadTime = 0.0f; if (ball.Speed() != 0.0) { lookAheadTime = toBall.magnitude / ball.Speed(); } //calculate where the ball will be at this time in the future target = ball.FuturePosition(lookAheadTime); //now seek to the predicted future position of the ball return(Arrive(target, Deceleration.fast)); }
public void ConfigureMinigame(int playerCount) { minigameTurn = 0; if (manager == null) { manager = MatchManager.instance; } int i, max = pivots.Length; // Cycle through each arrays and remove unecessary stuff for (i = max - 1; i > playerCount - 1; i--) { Destroy(balls[i].gameObject); Destroy(balls[i + max].gameObject); Destroy(pivots[i].gameObject); Destroy(interfaces[i].gameObject); } max = playerCount; SoccerBall[] newBalls = new SoccerBall[max * 2]; Transform[] newPivots = new Transform[max], newArrows = new Transform[max]; GameObject[] newInterfaces = new GameObject[max], newRotationCtrls = new GameObject[max]; Image[] newBars = new Image[max]; for (i = 0; i < max; i++) { newBalls[i] = balls[i]; newBalls[i + max] = balls[i + pivots.Length]; newPivots[i] = pivots[i]; newArrows[i] = arrows[i]; newInterfaces[i] = interfaces[i]; newRotationCtrls[i] = rotationCtrls[i]; newBars[i] = bars[i]; } balls = newBalls; pivots = newPivots; arrows = newArrows; interfaces = newInterfaces; rotationCtrls = newRotationCtrls; bars = newBars; }
// Use this for initialization void Start() { player = FindObjectOfType <MovementSoc>(); ball = FindObjectOfType <SoccerBall>(); if (textfile != null) { textLines = (textfile.text.Split('\n')); } if (endAtLine == 0) { endAtLine = textLines.Length - 1; } if (isActive) { EnableTextBox(); } else { DisableTextBox(); } }
private void Start() { soccerBall = GameObject.Find("Ball").GetComponent <SoccerBall>(); }
// Use this for initialization void Start() { SoccerBall = FindObjectOfType <SoccerBall>(); test = true; }
void TakeShot() { if( createBallFromBC ) { Rigidbody shot = Instantiate(ballProjectile, transform.position, transform.rotation) as Rigidbody; shot.freezeRotation = true; Physics.IgnoreCollision(gameObject.collider, shot.collider); Physics.IgnoreLayerCollision(shot.gameObject.layer, shot.gameObject.layer); shot.AddForce(ballLaunchForceVector_Mod, ForceMode.Impulse); Destroy (shot.gameObject, 3.0f); } else { if (soccerBall) { soccerBall.ballTrigger.DisableTrigger(NumOfUpdatesForShooting); soccerBall.rigidbody.velocity = Vector3.zero; soccerBall.rigidbody.angularVelocity = Vector3.zero; soccerBall.rigidbody.AddForce(ballLaunchForceVector_Mod, ForceMode.Impulse); soccerBall = null; isPlayerInPossessionOfABall = false; } } //Debug.DrawLine(transform.position, transform.position+(ballLaunchForceVector), Color.red, 2, false); }
private void Awake() { m_Ball = GetComponent <SoccerBall>(); m_Rigidbody = GetComponent <Rigidbody>(); }
public SteeringBehaviors(PlayerBase agent, SoccerPitch pitch, SoccerBall soccerBall) { this.player = agent; this.world = pitch; this.ball = soccerBall; }
Vector2 Interpose(SoccerBall ball, Vector2 pos, float distFromTarget) { return(Arrive(target + ((Vector2)ball.transform.position - target).normalized * distFromTarget, Deceleration.normal)); }
public FreeKick() { // Create a SoccerBall object representing the soccer ball. soccerBall = new SoccerBall(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.43, 0.038, 1.2, 0.5, 0.0, 0.0, 0.0, 0.0, -1.0, 10.0, 0.11, 294.0); // Set up images playerIcon = Image.FromFile("SoccerPlayerCartoon.gif"); playerWidth = playerIcon.Width; playerHeight = playerIcon.Height; ballIcon = Image.FromFile("SoccerBallCartoon.jpg"); // Create a Timer object that will be used // to slow the action down. gameTimer = new Timer(); gameTimer.Interval = 20; // delay in milliseconds. gameTimer.Tick += new EventHandler(ActionPerformed); // Create some Labels vxLabel = new Label(); vxLabel.Text = "Initial x-velocity (m/s)"; vxLabel.Font = new Font(vxLabel.Font, FontStyle.Bold); vxLabel.Top = 20; vxLabel.Left = 10; vxLabel.Width = 120; vyLabel = new Label(); vyLabel.Text = "Initial y-velocity (m/s)"; vyLabel.Font = new Font(vyLabel.Font, FontStyle.Bold); vyLabel.Top = 50; vyLabel.Left = 10; vyLabel.Width = 120; vzLabel = new Label(); vzLabel.Text = "Initial z-velocity (m/s)"; vzLabel.Font = new Font(vzLabel.Font, FontStyle.Bold); vzLabel.Top = 80; vzLabel.Left = 10; vzLabel.Width = 120; spinRateLabel = new Label(); spinRateLabel.Text = "Spin rate (rev/s)"; spinRateLabel.Font = new Font(spinRateLabel.Font, FontStyle.Bold); spinRateLabel.Top = 110; spinRateLabel.Left = 10; spinRateLabel.Width = 100; spinAxisLabel = new Label(); spinAxisLabel.Text = "Spin Axes"; spinAxisLabel.Font = new Font(spinAxisLabel.Font, FontStyle.Bold); spinAxisLabel.Top = 140; spinAxisLabel.Left = 10; spinAxisLabel.Width = 70; rxLabel = new Label(); rxLabel.Text = "rx"; rxLabel.Font = new Font(rxLabel.Font, FontStyle.Bold); rxLabel.Top = 170; rxLabel.Left = 50; rxLabel.Width = 50; ryLabel = new Label(); ryLabel.Text = "ry"; ryLabel.Font = new Font(ryLabel.Font, FontStyle.Bold); ryLabel.Top = 200; ryLabel.Left = 50; ryLabel.Width = 50; rzLabel = new Label(); rzLabel.Text = "rz"; rzLabel.Font = new Font(rzLabel.Font, FontStyle.Bold); rzLabel.Top = 230; rzLabel.Left = 50; rzLabel.Width = 50; // Create TextBox objects to display the inputs. vxTextBox = new TextBox(); vxTextBox.Width = 50; vxTextBox.Text = "-28.0"; vxTextBox.AutoSize = true; vxTextBox.Top = vxLabel.Top; vxTextBox.Left = 140; vyTextBox = new TextBox(); vyTextBox.Width = 50; vyTextBox.Text = "10.0"; vyTextBox.AutoSize = true; vyTextBox.Top = vyLabel.Top; vyTextBox.Left = 140; vzTextBox = new TextBox(); vzTextBox.Width = 50; vzTextBox.Text = "4.0"; vzTextBox.AutoSize = true; vzTextBox.Top = vzLabel.Top; vzTextBox.Left = 140; spinRateTextBox = new TextBox(); spinRateTextBox.Width = 50; spinRateTextBox.Text = "10.0"; spinRateTextBox.AutoSize = true; spinRateTextBox.Top = spinRateLabel.Top; spinRateTextBox.Left = 140; rxTextBox = new TextBox(); rxTextBox.Width = 60; rxTextBox.Text = "0.0"; rxTextBox.AutoSize = true; rxTextBox.Top = rxLabel.Top; rxTextBox.Left = 110; ryTextBox = new TextBox(); ryTextBox.Width = 50; ryTextBox.Text = "0.0"; ryTextBox.AutoSize = true; ryTextBox.Top = ryLabel.Top; ryTextBox.Left = 110; rzTextBox = new TextBox(); rzTextBox.Width = 50; rzTextBox.Text = "-1.0"; rzTextBox.AutoSize = true; rzTextBox.Top = rzLabel.Top; rzTextBox.Left = 110; // Create Button objects int buttonHeight = 30; int buttonWidth = 50; int buttonLeft = 20; fireButton = new Button(); fireButton.Text = "Fire"; fireButton.Height = buttonHeight; fireButton.Width = buttonWidth; fireButton.Top = 260; fireButton.Left = buttonLeft; fireButton.Click += new EventHandler(FireButtonClicked); resetButton = new Button(); resetButton.Text = "Reset"; resetButton.Height = buttonHeight; resetButton.Width = buttonWidth; resetButton.Top = 310; resetButton.Left = buttonLeft; resetButton.Click += new EventHandler(ResetButtonClicked); // Create a drawing panel. drawingPanel = new Panel(); drawingPanel.Width = 301; drawingPanel.Height = 301; drawingPanel.Left = 300; drawingPanel.Top = 20; drawingPanel.BorderStyle = BorderStyle.FixedSingle; // Add the GUI components to the Form this.Controls.Add(vxLabel); this.Controls.Add(vyLabel); this.Controls.Add(vzLabel); this.Controls.Add(spinRateLabel); this.Controls.Add(spinAxisLabel); this.Controls.Add(rxLabel); this.Controls.Add(ryLabel); this.Controls.Add(rzLabel); this.Controls.Add(vxTextBox); this.Controls.Add(vyTextBox); this.Controls.Add(vzTextBox); this.Controls.Add(spinRateTextBox); this.Controls.Add(rxTextBox); this.Controls.Add(ryTextBox); this.Controls.Add(rzTextBox); this.Controls.Add(fireButton); this.Controls.Add(resetButton); this.Controls.Add(drawingPanel); // Set the size and title of the form this.Width = 650; this.Height = 400; this.Text = "Free Kick"; // Center the form on the screen and make // it visible. this.StartPosition = FormStartPosition.CenterScreen; this.Visible = true; // Update the GUI display UpdateDisplay(); }
public void setTarget(SoccerBall target) { m_target = target; }
private Vector3 Interpose(SoccerBall ball, Vector3 targetPos, float distFormTarget) { //TODO Vector3 direction = ball.transform.position - targetPos; return Arrive(direction.normalized * distFormTarget,deceleration_type.noraml); }
private Vector3 Pursuit(SoccerBall target) { Vector3 toTarget = target.transform.position - m_controller.transform.position; float distance = toTarget.magnitude; float time = 0.0f; if(target.Velocity.magnitude > 0.0f) time = distance / target.Velocity.magnitude; Vector3 targetPos = target.FuturePosition(time); return Arrive(targetPos,deceleration_type.fast); }