private void HandleCollision(MoveBall b1, MoveBall b2) { //collision detected: the collision has happened anytime between the previous frame and this one. //find how much time has past since the the collision MyVector3 relVelocity = MoveBall.RelativeVelocity(b2, b1); // V° rel velocity (const) MyVector3 relPosition = MoveBall.RelativePosition(b2, b1); // P° rel position at t=0 // relative position P(t) = P° - V° * t // the collision happens when |P(t)| = 2 * radius // <P(t)|P(t)> = <(P° - V° * t)|(P° - V° * t)> = 4 * radius^2 // solve the above quadratic eq. for t float term1 = MyVector3.Dot(relVelocity, relPosition); float term2 = MyVector3.Dot(relPosition, relPosition); float term3 = MyVector3.Dot(relVelocity, relVelocity); float rootSquared = term1 * term1 - term3 * (term2 - 4 * SnookerBall.radius * SnookerBall.radius); if (rootSquared < 0) { rootSquared = 0; } float timeAfterCollision = (term1 + Mathf.Sqrt(rootSquared)) / term3; b1.MoveByVector(b1.GetVelocity().Scale(-timeAfterCollision)); //minus sign because we are moving the ball back in time b2.MoveByVector(b2.GetVelocity().Scale(-timeAfterCollision)); //minus sign because we are moving the ball back in time relPosition = MoveBall.RelativePosition(b2, b1); //vector joining the centers of the 2 balls MyVector3 b1_parallel = b1.GetLinearMomentum().ParallelComponent(relPosition); MyVector3 b1_perpendicular = b1.GetLinearMomentum().NormalComponent(relPosition); MyVector3 b2_parallel = b2.GetLinearMomentum().ParallelComponent(relPosition); MyVector3 b2_perpendicular = b2.GetLinearMomentum().NormalComponent(relPosition); //the two ball exchange the parallel components of their linear momenta //this is only valid in the case of the masses being the same b1.SetLinearMomentum(MyVector3.Add(b1_perpendicular, b2_parallel)); b2.SetLinearMomentum(MyVector3.Add(b2_perpendicular, b1_parallel)); }
private void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("Ball")) { Debug.Log("충돌"); tempBallPos = other.transform.position; tempBallScale = other.transform.localScale; CheckCollisionSide(); MoveBall tempMoveBall = other.gameObject.GetComponent <MoveBall>(); if (!tempMoveBall.frameCollisionCheck) { if (shortestSide < 3) { other.gameObject.GetComponent <MoveBall>().TurnTheBall(2); } else { other.gameObject.GetComponent <MoveBall>().TurnTheBall(1); } tempMoveBall.frameCollisionCheck = true; // gameObject.SetActive(false); GetDamage(other.gameObject.GetComponent <BallInfo>().damage); } shortestSide = 0; } }
public void InitMovePieceTests() { BoardStrategy strat = BoardStrategy.Standard; g = new GameBuilder().SetBoard(3, strat).SetPlayer0("Clément", "vert").SetPlayer1("Pierre", "orange").Build(); commandMove = new MoveBall(0, 1, 0, 0); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var job = new MoveBall { }; return(job.Schedule(this, inputDeps)); }
public void DoMoveBallTest3() { BoardStrategy strat = BoardStrategy.Standard; g = new GameBuilder().SetBoard(5, strat).SetPlayer0("Clément", "vert").SetPlayer1("Pierre", "orange").Build(); commandMove = new MoveBall(0, 2, 0, 1); //Console.Write(g.Board.ToString()); //Console.Write(commandMove.ToString()); commandMove.Do(g); //Console.Write(g.Board.ToString()); TileTypes[,] expectedTilesSize5 = { { TileTypes.PiecePlayer0, TileTypes.BallPlayer0, TileTypes.PiecePlayer0, TileTypes.PiecePlayer0, TileTypes.PiecePlayer0 }, { TileTypes.Default, TileTypes.Default, TileTypes.Default, TileTypes.Default, TileTypes.Default }, { TileTypes.Default, TileTypes.Default, TileTypes.Default, TileTypes.Default, TileTypes.Default }, { TileTypes.Default, TileTypes.Default, TileTypes.Default, TileTypes.Default, TileTypes.Default }, { TileTypes.PiecePlayer1, TileTypes.PiecePlayer1, TileTypes.BallPlayer1, TileTypes.PiecePlayer1, TileTypes.PiecePlayer1 } }; for (int i = 0; i < g.Board.BoardSize; i++) { for (int j = 0; j < g.Board.BoardSize; j++) { Assert.IsTrue(g.Board.Tiles[i, j] == expectedTilesSize5[i, j]); } } }
private void Awake() { Assert.IsNotNull(this.guiText); Assert.IsNotNull(this.ball); this._moveBall = this.ball.GetComponent <MoveBall>(); Assert.IsNotNull(this._moveBall); }
private void Update() { if (GameOver) { restartPanel.SetActive(true); } else { restartPanel.SetActive(false); if (ballInScene == null) { ballInScene = GameObject.FindGameObjectWithTag("Ball"); } if (ballInScene != null) { moveBallScript = ballInScene.GetComponent <MoveBall>(); throwBallScript = ballInScene.GetComponent <ThrowBall>(); } if (IsBallThrown && ThrustPower != 0) { moveBallScript.enabled = false; throwBallScript.enabled = true; } } }
// Start is called before the first frame update void Start() { moveBall = ball.GetComponent <MoveBall>(); moveBallRigidbody = ball.GetComponent <Rigidbody2D>(); animateTrump1 = player1.GetComponent <AnimateTrump>(); animateTrump2 = player2.GetComponent <AnimateTrump>(); }
public static void Main() { System.Console.WriteLine("assignment 3"); MoveBall mb = new MoveBall(); Application.Run(mb); System.Console.WriteLine("end of assignment 3"); }
private void OnEnable() { /// Publishers. _moveBall = FindObjectOfType <MoveBall>(); Assert.IsNotNull(_moveBall); /// Subscribe to events. _moveBall.HitBackWall += OnBallHitBackWall; }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var job = new MoveBall { forceAppliedMult = PlayTimeSettings.forceAppliedMult, forceMult = PlayTimeSettings.forceMult }; return(job.Schedule(this, inputDeps)); }
private void startBallButton_Click(object sender, EventArgs e) { moveBalls = new List <MoveBall>(); for (int i = 0; i < countBalls; i++) { var moveBall = new MoveBall(this); moveBalls.Add(moveBall); moveBall.Start(); } }
// Start is called before the first frame update void Start() { //find the object ball and get the component moveBall Ball = GameObject.Find("Ball").GetComponent <MoveBall>(); TextLives.text = preTextScore2 + lives; Scoretxt.text = preTextScore + score.ToString("D8"); LoadLevel(); //initialize first level bestScore = PlayerPrefs.GetInt("Score", 0); //read the old high score }
public void MoveBallTest() { g.Update(new MoveBall(0, 1, 0, 0)); MoveBall cmd = (MoveBall)g.CommandHistory.Pop().GetCommand(); Assert.IsTrue(cmd.NextX == 0); Assert.IsTrue(cmd.NextY == 0); Assert.IsTrue(cmd.PrevX == 0); Assert.IsTrue(cmd.PrevY == 1); Assert.IsTrue(g.UndoHistory.Count == 0); }
private void SetCurrentBall(int number) { currentBall = balls[number].GetComponent <MoveBall>(); touchHandler.ballMovement = balls[number].GetComponent <MoveBall>(); mainCamera.targetTransform = balls[number].transform; speedController.ballMovement = balls[number].GetComponent <MoveBall>(); speedController.slider.value = currentBall.GetVelocity() / 100f; }
void MakeBall() { ball = GameObject.CreatePrimitive(PrimitiveType.Sphere); Color color = createRandomColor(); MeshRenderer ballRenderer = ball.GetComponent <MeshRenderer>(); Material newMaterial = new Material(Shader.Find("Diffuse")); newMaterial.color = color; ballRenderer.material = newMaterial; //add necessary components //add move ball MoveBall moveball = ball.AddComponent <MoveBall>(); }
private void Start() { BallCurrentState = State.Still; BallThrowPower = ThrowPower.NoPower; moveBallScript = gameObject.GetComponent <MoveBall>(); throwBallScript = gameObject.GetComponent <ThrowBall>(); rb = gameObject.GetComponent <Rigidbody>(); stickCollisionScript = GameObject.Find("Stick").GetComponent <Stick>(); maxDistance = 49.51f; finishCollider = GameObject.Find("Finish Collider").GetComponent <FinishCollider>(); }
void Start() { /* Inputs | Outputs * | * Ball X | Paddle Velocity Y * Ball Y | * Ball Speed X | * Ball Speed Y | * Paddle X | * Paddle Y | */ ball = ballRb.GetComponent <MoveBall> (); inputValues = new double[6]; outputs = new double[1]; brain.StartNeuralNetwork(6, 1); }
private void OnTriggerEnter2D(Collider2D other) { GameObject.Find("GameManager").GetComponent <AudioSource>().Play(); if (other.gameObject.CompareTag("paddle") && !isRunned) { isRunned = true; var extraBall = Instantiate(ball, ball.transform, true); MoveBall moveBall = extraBall.GetComponent <MoveBall>(); moveBall.isDupBall = true; Destroy(gameObject); } if (other.gameObject.CompareTag("death")) { Destroy(gameObject); } }
private void Start() { Time.timeScale = 1f; GameIsOver = false; LevelWon = false; Score = 0; Coin = 0; moveBallScript = GameObject.Find("Ball").GetComponent <MoveBall>(); moveBallScript.enabled = true; throwBallScript = GameObject.Find("Ball").GetComponent <ThrowBall>(); throwBallScript.enabled = false; ball = GameObject.Find("Ball"); gameOverScreen.SetActive(false); levelWonScreen.SetActive(false); }
// Use this for initialization public void Start() { DayAndNightCycle(true); settingsCode = GameObject.FindObjectOfType <Settings>(); paddleSensitivity = settingsCode.Sensitivity; ballCode = ballObject.GetComponent <MoveBall>(); ballSprite = ballObject.GetComponent <SpriteRenderer>(); paddleCode = paddleObject.GetComponent <MovePaddle>(); paddleSprite = paddleObject.GetComponent <SpriteRenderer>(); paddleSpriteOGSize = paddleSprite.size; scoreText.text = "SCORE: " + points.ToString("D8"); powerTx.enabled = false; SetCreditText(); settingsCode.GetLeaderboard(); bestScore = settingsCode.LeaderboardScores[0]; rankedText.text = string.Empty; LoadLvl(); InitBallSpeed(); }
// Use this for initialization void Start() { Time.timeScale = 1f; GameParams.SetScore(0); _nextScene = ""; MoveBall.ClearBallCount(); _instance = this; /* * // 敵を出現 * for (int i = 0; i < TekiCount; i++) { * Instantiate (prefTeki); * } * // アイテムを出現 * for (int i = 0; i < ItemCount; i++) { * Instantiate (prefItem); * } */ }
// Use this for initialization void Start() { Time.timeScale = 1f; GameParams.SetScore(0); _nextScene = ""; MoveBall.ClearBallCount(); _instance = this; /* * // 敵を出現 * for (int i = 0; i < TekiCount; i++) { * Instantiate (prefTeki); * } * // アイテムを出現 * for (int i = 0; i < ItemCount; i++) { * Instantiate (prefItem); * } */ // 変数にコンポーネント格納 sound01 = GetComponent <AudioSource>(); }
void OnTriggerEnter2D(Collider2D col) { if (col.CompareTag("Ball")) { Debug.Log("충돌"); tempBallPos = col.transform.position; tempBallScale = col.transform.localScale; CheckCollisionSide(); MoveBall tempMoveBall = col.gameObject.GetComponent <MoveBall>(); if (!tempMoveBall.frameCollisionCheck) { if (shortestSide < 3) { tempMoveBall.TrunTheBall(2); } else { tempMoveBall.TrunTheBall(1); } tempMoveBall.frameCollisionCheck = true; tempMoveBall = null; //gameObject.SetActive(false); GetDamage(col.gameObject.GetComponent <BallInfo>().damage); } else { tempMoveBall = null; } shortestSide = 0; } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { EntityCommandBuffer entityOriginsCommandBuffer = new EntityCommandBuffer(Allocator.TempJob, PlaybackPolicy.SinglePlayback); Entities.WithNone <BallOriginalTranslation>().ForEach((Entity entity, Translation translation, SphereId sphereId) => { entityOriginsCommandBuffer.AddComponent(entity, new BallOriginalTranslation { Value = translation.Value }); }).Run(); entityOriginsCommandBuffer.Playback(EntityManager); entityOriginsCommandBuffer.Dispose(); var moveBallJob = new MoveBall { TranslationType = GetArchetypeChunkComponentType <Translation>(), BallOriginalTranslationType = GetArchetypeChunkComponentType <BallOriginalTranslation>(true), LastSystemVersion = LastSystemVersion, ElapsedTime = Time.ElapsedTime }; var moveBallJobHandle = moveBallJob.Schedule(m_Group, inputDeps); return(moveBallJobHandle); }
void Start() { _ballMover = ball.GetComponent <MoveBall>(); _line = new Line(new Coordinate(ball.transform.position), lineEnd.position - ball.transform.position); _plane = new Plane(new Coordinate(planeOrigin.position), planeVectorV.position - planeOrigin.position, planeVectorU.position - planeOrigin.position); _line.Draw(0.1f, Color.cyan); PopulatePlaneWithSpheres(); //ShowIntersectionPoint(); var ballPathSegment = CalculateIntersection(); if (ballPathSegment == null) { return; } _ballMover.OnIntersectionCalculate(ballPathSegment); var reflectionLineSegment = ballPathSegment.ReflectsFrom(_plane); reflectionLineSegment.Draw(0.1f, Color.magenta); _ballMover.OnReflectionCalculate(reflectionLineSegment); }
private void Awake() { moveBall = GetComponent <MoveBall>(); }
//relative position of ball 2 with respect of ball 1 public static MyVector3 RelativePosition(MoveBall b2, MoveBall b1) { return(MyVector3.Subtract(b2.position, b1.position)); }
//relative velocity of ball 2 with respect of ball 1 public static MyVector3 RelativeVelocity(MoveBall b2, MoveBall b1) { return(MyVector3.Subtract(b2.linearMomentum, b1.linearMomentum).Scale(1 / SnookerBall.mass)); }
public void DoMoveBallTest2() { commandMove = new MoveBall(-1, -1, 0, 0); commandMove.Do(g); Assert.IsTrue(g.Board.Tiles[0, 0] == TileTypes.BallPlayer0); }