public static Snowball2 getSmallestBall(Snowball2 ball1, Snowball2 ball2) { if (ball1.Scale < ball2.Scale) { return(ball1); } else { return(ball2); } }
public static bool checkIfBallsAreCloseToEachOther(Snowball2 ball1, Snowball2 ball2) { Vector3 distanceOfBothBalls = ball1.transform.position - ball2.transform.position; float radiusSumOfSnowballs = ball1.Scale / 2 + ball2.Scale / 2; Snowball2 smallestBall = getSmallestBall(ball1, ball2); float snowballMergeThreshold = smallestBall.Scale * snowballMergeThresholdMultiplier; float mergeDistance = radiusSumOfSnowballs - snowballMergeThreshold; return(distanceOfBothBalls.magnitude < mergeDistance); }
public void Reset() { PlayersLeftBall = null; PlayersRightBall = null; OpponentLeftBall = null; OpponentRightBall = null; PlayersBalls = new Dictionary <int, Snowball2>(); OpponentsBalls = new Dictionary <int, Snowball2>(); Health = 1f; SnowBallIndex = 0; }
public void RpcDecreaseHealthOfOpponentsSnowBall(int id) { if (!isLocalPlayer) { if (ballDatabase.PlayersBalls.ContainsKey(id)) { Snowball2 opponentsBall = ballDatabase.PlayersBalls[id]; opponentsBall.Health--; } else { Debug.Log(string.Format( "RpcDecreaseHealthOfOpponentsSnowBall PlayersBalls did not contain the Key {0}", id)); } } }
public void RpcDeleteSnowBall(int id) { if (!isLocalPlayer) { if (ballDatabase.OpponentsBalls.ContainsKey(id)) { Snowball2 ball = ballDatabase.OpponentsBalls[id]; GameObject.Destroy(ball.gameObject); ballDatabase.OpponentsBalls.Remove(id); } else { Debug.Log(string.Format( "RpcDeleteSnowBall OpponentsBalls did not contain the Key {0}", id)); } } }
private void HandleMouseKeyboardInput() { float xAxisValue = Input.GetAxis("Horizontal"); float zAxisValue = Input.GetAxis("Vertical"); transform.Translate(new Vector3(xAxisValue, 0.0f, zAxisValue)); yaw += speedH * Input.GetAxis("Mouse X"); pitch -= speedV * Input.GetAxis("Mouse Y"); transform.eulerAngles = new Vector3(pitch, yaw, 0.0f); if (Input.GetMouseButtonDown(0)) { } if (Input.GetKeyUp(KeyCode.Alpha1)) { ballToThrowScale -= 0.05f; } if (Input.GetKeyUp(KeyCode.Alpha2)) { ballToThrowScale += 0.05f; } if (Input.GetKeyUp(KeyCode.Alpha3)) { ballToThrowVelocityMultiplier -= 3f; } if (Input.GetKeyUp(KeyCode.Alpha4)) { ballToThrowVelocityMultiplier += 3f; } if (Input.GetKeyUp(KeyCode.Alpha9)) { var go = GameObject.Instantiate(snowBallPrefab); go.transform.position = nonVrCamera.transform.position + nonVrCamera.transform.forward * 2; Rigidbody rigidbody = go.GetComponent <Rigidbody>(); rigidbody.velocity = nonVrCamera.transform.forward * ballToThrowVelocityMultiplier; go.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); Snowball2 BallInHand = go.GetComponent <Snowball2>(); BallInHand.IsLocalBall = true; BallInHand.Scale = ballToThrowScale; BallInHand.Health = ballToThrowScale; SpawnBallOnOpponentsClient(BallInHand); } }
public void RpcUpdateMySnowBall(int id, Vector3 position, Vector3 velocity, bool useGravity, float scale, float health) { if (!isLocalPlayer) { if (ballDatabase.OpponentsBalls.ContainsKey(id)) { Snowball2 ball = ballDatabase.OpponentsBalls[id]; ball.transform.position = position; ball.Rigidbody.velocity = velocity; ball.Scale = scale; ball.Health = health; ball.UseGravity = useGravity; } else { Debug.Log("RpcUpdateMySnowBall OpponentsBalls did not contain the Key"); } } }
public void RpcSpawnSnowBall(int id, Vector3 position, Vector3 velocity, bool useGravity, float scale, float health) { if (!isLocalPlayer) { var go = GameObject.Instantiate(snowBallPrefab); go.transform.position = position; go.GetComponent <Rigidbody>().velocity = velocity; Snowball2 ball = go.GetComponent <Snowball2>(); ball.UseGravity = useGravity; ball.IsLocalBall = false; ball.Scale = scale; ball.Health = health; ball.Id = id; ballDatabase.OpponentsBalls.Add(id, ball); } }
private void FixedUpdate() { var balls = player.PlayersBalls.Select(d => d.Value).ToList(); Snowball2 ballInGrabDistance = null; for (int i = 0; i < balls.Count; i++) { var ball = balls[i]; if (ball != null) { Vector3 distanceToBallCenter = ball.transform.position - transform.position; float ballRadius = ball.Scale / 2; bool ballIsWithinGrabDistance = distanceToBallCenter.magnitude < ballRadius; if (ballIsWithinGrabDistance) { ballInGrabDistance = ball; } } } if (IsNotHoldingBall && HoldInputPressed && HandIsInSnow) { CreateBallInHand(); } else if (IsNotHoldingBall && HoldInputPressed && ballInGrabDistance != null) { GrabBall(ballInGrabDistance.gameObject); } else if (IsHoldingBall && HoldInputReleased) { ThrowBall(); } if (BallsAreCloseToEachOther) { MergeBalls(); } }
public void SpawnBallOnOpponentsClient(Snowball2 BallInHand) { BallInHand.Id = ballDatabase.SnowBallIndex++; ballDatabase.PlayersBalls.Add(BallInHand.Id, BallInHand); CmdSpawnSnowBall(BallInHand.Id, BallInHand.transform.position, BallInHand.Rigidbody.velocity, BallInHand.UseGravity, BallInHand.Scale, BallInHand.Health); }