private void SetThrowDirection(ViolaController.HandType handType, ref Vector3 throwAngle, Rigidbody currentBall) { if (handType == ViolaController.HandType.Left) { throwAngle.x *= -1; currentBall.transform.position = Vector3.MoveTowards(currentBall.transform.position, leftHand.position, 0.7f); } else { currentBall.transform.position = Vector3.MoveTowards(currentBall.transform.position, rightHand.position, 0.7f); } }
private GameObject GetBallToThrow(ViolaController.HandType hand) { foreach (GameObject ball in ballsInCatchZone) { if ((hand == ViolaController.HandType.Right && ball.transform.position.x < 0) || (hand == ViolaController.HandType.Left && ball.transform.position.x > 0)) { return(ball); } } return(null); }
// This is the consequence of derping with lerping. private void FullSpagetti(ViolaController.ThrowType throwType, ViolaController.HandType hand, GameObject ball) { Animator ballAnimator = ball.GetComponent <Animator>(); ballAnimator.enabled = true; if (hand == ViolaController.HandType.Left) { if (throwType == ViolaController.ThrowType.HighThrow) { ballAnimator.Play("rightToLeftUP", 0, 0f); } else if (throwType == ViolaController.ThrowType.MidThrow) { ballAnimator.Play("rightToLeftMIDDLE", 0, 0f); } else if (throwType == ViolaController.ThrowType.FloorBounce) { ballAnimator.Play("rightToLeftDOWN", 0, 0f); } } if (hand == ViolaController.HandType.Right) { if (throwType == ViolaController.ThrowType.HighThrow) { ballAnimator.Play("leftToRightUP", 0, 0f); } else if (throwType == ViolaController.ThrowType.MidThrow) { ballAnimator.Play("LeftToRightMiddle", 0, 0f); } else if (throwType == ViolaController.ThrowType.FloorBounce) { ballAnimator.Play("LeftToRightDown", 0, 0f); } } }
/// <summary> /// Checks how to player has swiped. /// </summary> private void CheckSwipe(int i) { Vector3 directionVector = lastPosition[i] - firstPosition[i]; if (!SwipedLongEnough(directionVector)) { return; } SwipeDirection direction; if (Mathf.Abs(directionVector.x) > Mathf.Abs(directionVector.y)) { direction = HorizontalSwipe(i); } else { direction = VerticalSwipe(i); } screenSide = SwipeLocation(i); throwType = ComputeThrowType(direction); }
IEnumerator LerpToHandAndPlayAnim(ViolaController.ThrowType throwType, ViolaController.HandType hand, GameObject ball) { Animator ballAnimator = ball.GetComponent <Animator>(); Debug.Log("Lerping"); float duration = 0.02f; if (hand == ViolaController.HandType.Left) { float journey = 0f; Vector3 currentpos = ball.transform.position; ballAnimator.enabled = false; while (journey <= duration) { journey = journey + Time.deltaTime; float percent = Mathf.Clamp01(journey / duration); ball.transform.position = Vector3.Lerp(currentpos, lerpLeftHandTarget, percent); yield return(null); } yield return(new WaitForSeconds(duration)); ballAnimator.enabled = true; if (throwType == ViolaController.ThrowType.HighThrow) { ballAnimator.Play("rightToLeftUP", 0, 0f); } else if (throwType == ViolaController.ThrowType.MidThrow) { ballAnimator.Play("rightToLeftMIDDLE", 0, 0f); } else if (throwType == ViolaController.ThrowType.FloorBounce) { ballAnimator.Play("rightToLeftDOWN", 0, 0f); } Debug.Log("gottem"); } else if (hand == ViolaController.HandType.Right) { float journey = 0f; Vector3 currentpos = ball.transform.position; ballAnimator.enabled = false; while (journey <= duration) { journey = journey + Time.deltaTime; float percent = Mathf.Clamp01(journey / duration); ball.transform.position = Vector3.Lerp(currentpos, lerpRightHandTarget, percent); yield return(null); } yield return(new WaitForSeconds(duration)); ballAnimator.enabled = true; if (throwType == ViolaController.ThrowType.HighThrow) { ballAnimator.Play("leftToRightUP", 0, 0f); } else if (throwType == ViolaController.ThrowType.MidThrow) { ballAnimator.Play("LeftToRightMiddle", 0, 0f); Debug.Log("gottem for real"); } else if (throwType == ViolaController.ThrowType.FloorBounce) { ballAnimator.Play("LeftToRightDown", 0, 0f); } Debug.Log("gottem for real"); } yield return(null); }
// These functions rely on that the two hands are at positive/negative X positions! public void Throw(ViolaController.ThrowType throwType, ViolaController.HandType hand) { var ball = GetBallToThrow(hand); if (ball == null) { return; } var anim = ball.GetComponent <Animator>(); if (anim.isActiveAndEnabled && ball.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).normalizedTime < 0.5) { return; } //Rigidbody ballRigidBody = ball.GetComponent<Rigidbody>(); //ball.GetComponent<Animator>().enabled = true; AkSoundEngine.SetRTPCValue("rightCollider", 0.0f); FullSpagetti(throwType, hand, ball); //IEnumerator coroutine = LerpToHandAndPlayAnim(throwType, hand, ball); //StartCoroutine(coroutine); if (hand == ViolaController.HandType.Left) { AkSoundEngine.PostEvent("ColliderLeft_event", gameObject); } else if (hand == ViolaController.HandType.Right) { AkSoundEngine.PostEvent("ColliderRight_event", gameObject); } //ballRigidBody.useGravity = false; //ballRigidBody.velocity = Vector3.zero; //ballRigidBody.isKinematic = true; ball.GetComponent <Ball>().wasPerfectlyThrown = GotPerfectCatch(ball); //bool perfect = GotPerfectCatch(ball); //ball.GetComponent<Ball>().wasPerfectlyThrown = perfect; //if (perfect) //{ // //flameMeshShader.SetActive(true); // //displacementAmounts += new Vector4(0, 0, -2, 0); // //Debug.Log("happened"); //} //Vector3 throwVector = +(throwType, ball); //SetThrowDirection(hand, ref throwVector, ballRigidBody); //ballRigidBody.isKinematic = false; //if (ballRigidBody.drag > 0) // ballRigidBody.drag = 0; //ballRigidBody.AddForce(throwVector); //BallLeavesHand(ball.GetComponent<Collider>()); throwCount++; if (throwCount >= numberOfBalls) { SceneController.IsPlaying = true; } }