//gameObject.transform.GetChild(0).GetComponent<ParticleSystem>().enableEmission = false; //Firepower //child0 //element //child1 // Use this for initialization void Start () { OriginalPositionHand = new Vector3(0,0,0); //currentSpeed = 10f; HandBallPosition = GameObject.Find("RightHand").transform.position; speedFactor = 10f; WaitingForPlayerKick = false; isStopped = false; hasCollided = true; ObjectBall = GameObject.Find("ObjectBall"); OriginPoint = GameObject.Find("Center"); GameControlObject = GameObject.Find("GameController"); KinectObject = GameObject.Find("KinectController"); // Get the position of the respawning ball RespanwPoint = OriginPoint.transform.GetChild(0); //gameObject.GetComponent<Rigidbody>().velocity = new Vector3(1, 1, 0); gameController = (GameController)GameControlObject.GetComponent(typeof(GameController)); KinectController = (KinectTranslate)KinectObject.GetComponent(typeof(KinectTranslate)); currentSpeed = gameController.BallSpeed; Vector3 velocityBall = gameController.StartKick(currentSpeed, 1); //Vector3 velocityBall = new Vector3(currentSpeed, currentSpeed / 2, currentSpeed); GetComponent<Rigidbody>().velocity = velocityBall; //GetComponent<Rigidbody>().AddForce(velocityBall); audioS = gameObject.AddComponent<AudioSource>(); if (gameController.leftie) { theArm = KinectController.leftArm; } else { theArm = KinectController.rightArm; } }
// Update is called once per frame void Update () { //gameObject.GetComponent<Rigidbody>().AddForce(transform.right * 3.0f); //gameObject.GetComponent<Rigidbody>().AddForce(transform.forward * 3.0f); //transform.Translate(Vector3.forward * MoveSpeed * Time.deltaTime); Vector3 ActualHandBallPosition; bool gestureMade = false; bool StaticForFrames = false; bool loop_done1 = false; float DistanceSwift = 1f; if (gameController.leftie) { theArm = KinectController.leftArm; } else { theArm = KinectController.rightArm; } if (isStopped) GetComponent<Rigidbody>().velocity = new Vector3(0, 0, 0); if (gameController.body != "undef") { ActualHandBallPosition = theArm.ObjHand.transform.position; if (isStopped && WaitingForPlayerKick) { gameObject.transform.position = ActualHandBallPosition; if (!KinectController.checkRayOnPoint(0.5f, OriginalPositionHand, ActualHandBallPosition) && ActualHandBallPosition.z - OriginalPositionHand.z > 0.3f) { print("BIG MOVE DETECTED"); // if MOVE UP ->SHOOT THE BALL in the direction //if (KinectController.MovingUp(KinectController.OriginalPositionRightHand, HandBallPosition)) print("Moving UP: " + OriginalPositionHand + "...." + HandBallPosition); Vector3 velocityBall = KinectController.JointRelativePosition(OriginalPositionHand, ActualHandBallPosition, false); GetComponent<Rigidbody>().velocity = velocityBall * currentSpeed; WaitingForPlayerKick = false; isStopped = false; theArm.deactivated = false; } else { OriginalPositionHand = ActualHandBallPosition; WaitingForPlayerKick = true; theArm.deactivated = true; } } /* //ActualHandBallPosition = theArm.ObjHand.transform.position; //print(ActualHandBallPosition); // DEBUG if (theArm.ObjHand != null) { ActualHandBallPosition = theArm.ObjHand.transform.position; //print("1: GOT HAND POSITION: " + ActualHandBallPosition + " \n"); } else ActualHandBallPosition = new Vector3(0,0,0); print("WaitingForPlayerKick:" + WaitingForPlayerKick); if (isStopped && WaitingForPlayerKick && ActualHandBallPosition != new Vector3(0, 0, 0)) { //KinectController.CheckStaticFrames(ref KinectController.rightArm); //print("Ball Position updated to: " + ActualHandBallPosition); //Debugg gameObject.transform.position = ActualHandBallPosition; StaticForFrames = KinectController.CheckStaticFrames(ref theArm); gestureMade = KinectController.checkRayOnPoint(3f, HandBallPosition, ActualHandBallPosition); //KinectController.MovingUp(HandBallPosition, ActualHandBallPosition); if(!StaticForFrames) { if (theArm.Opointer.x == 0 && theArm.Opointer.y == 0 && theArm.Opointer.z == 0) { print("2.1 Set up contruction point first time"); theArm.frameCount = 0; theArm.rayColor = Color.white; theArm.Opointer = theArm.pointer; OriginalPositionHand = theArm.ObjHand.transform.position; //Impact = theArm.ObjectHit; loop_done1 = true; } //CASE 2: On range of the Opoint else if (!loop_done1 && KinectController.checkRayOnPoint(2f, OriginalPositionHand, ActualHandBallPosition)) { print("2.2 Counting frames"); theArm.frameCount++; //print("dEBUGGING: " + rightArm.pointer); } //CASE 3: too far away -> reset // Exception if we are LISTENING TO GESTURES else if (!loop_done1 && !KinectController.checkRayOnPoint(DistanceSwift, OriginalPositionHand, ActualHandBallPosition) && !StaticForFrames) { print("2.3 Reseted point to..."); theArm.frameCount = 0; //if (checkValidPointer(rightArm.pointer)) loop_done1 = true; theArm.Opointer = new Vector3(0, 0, 0); OriginalPositionHand = new Vector3(0, 0, 0); StaticForFrames = false; } } if (StaticForFrames) { //player kick KinectController.MovingUp(HandBallPosition, ActualHandBallPosition) Vector3 velocityBall = KinectController.JointRelativePosition(KinectController.OriginalPositionRightHand, ActualHandBallPosition, false); //GetComponent<Rigidbody>().velocity = velocityBall; print("3 frame test passed"); // If we move away we will either SHOOT the ball OR DISMISS the point if (!KinectController.checkRayOnPoint(1f, OriginalPositionHand, ActualHandBallPosition)) { print("4. BIG MOVE DETECTED"); // if MOVE UP ->SHOOT THE BALL in the direction //if (KinectController.MovingUp(KinectController.OriginalPositionRightHand, HandBallPosition)) print("Moving UP: "+ OriginalPositionHand + "...."+ HandBallPosition); GetComponent<Rigidbody>().velocity = velocityBall * currentSpeed; WaitingForPlayerKick = false; isStopped = false; theArm.deactivated = false; } } else { HandBallPosition = ActualHandBallPosition; } } */ } if (!isStopped) { Vector3 currentVelocity = GetComponent<Rigidbody>().velocity; var newVelocity = currentVelocity.normalized * currentSpeed; GetComponent<Rigidbody>().velocity = Vector3.Lerp(currentVelocity, newVelocity, Time.deltaTime * gameController.BallSpeed); } //print(RespanwPoint.name); //print(RespanwPoint.transform.position); }