//----------------------------------------------- // Use this for initialization void Start() { if (this.transform.name == "GoalKeeper_Local") { TeamName = "Local"; playerTeam = GameObject.Find("Local").GetComponent <STeam>(); opponentTeam = GameObject.Find("Visit").GetComponent <STeam>(); Opponents = opponentTeam.Visitors; Teammates = playerTeam.Locals; } else { TeamName = "Visit"; playerTeam = GameObject.Find("Visit").GetComponent <STeam>(); opponentTeam = GameObject.Find("Local").GetComponent <STeam>(); Opponents = opponentTeam.Locals; Teammates = playerTeam.Visitors; } scorerTime = GameObject.FindObjectOfType(typeof(ScorerTimeHUD)) as ScorerTimeHUD; listPosicion = new List <string>(); initial_Position = transform.position; state = GoalKeeper_State.RESTING; GetComponent <Animation>()["running"].speed = 1.0f; GetComponent <Animation>()["goalkeeper_clear_right_up"].speed = 1.0f; GetComponent <Animation>()["goalkeeper_clear_left_up"].speed = 1.0f; GetComponent <Animation>()["goalkeeper_clear_right_down"].speed = 1.0f; GetComponent <Animation>()["goalkeeper_clear_left_down"].speed = 1.0f; }
public CapsuleCollider capsuleCollider; // A reference to teh collider of the main body of the keeper // Use this for initialization void Start() { initial_Position = transform.position; //store the keepers initial position state = GoalKeeper_State.RESTING; // initial_Position = new Vector3(transform.position.x, transform.position.y, transform.position.z); animation["playerIdle"].speed = 1.0f; }
/*This is the collision for when the keeper saves the ball. I change the state to make him return to his original * position */ void OnCollisionStay(Collision coll) { if (coll.collider.transform.gameObject.tag == "Ball" && state != GoalKeeper_State.JUMP_LEFT && state != GoalKeeper_State.JUMP_RIGHT && state != GoalKeeper_State.JUMP_LEFT_HIGH && state != GoalKeeper_State.JUMP_RIGHT_HIGH) { state = GoalKeeper_State.MOVE_TO_RESTING; } }
// Use this for initialization void Start() { initial_Position = transform.position; state = GoalKeeper_State.RESTING; GetComponent <Animation>()["running"].speed = 1.0f; GetComponent <Animation>()["goalkeeper_clear_right_up"].speed = 1.0f; GetComponent <Animation>()["goalkeeper_clear_left_up"].speed = 1.0f; GetComponent <Animation>()["goalkeeper_clear_right_down"].speed = 1.0f; GetComponent <Animation>()["goalkeeper_clear_left_down"].speed = 1.0f; }
// Use this for initialization void Start() { initial_Position = transform.position; state = GoalKeeper_State.RESTING; GetComponent <Animation>()["run"].speed = 1.0f; GetComponent <Animation>()["goalkeeper_high_right"].speed = 1.0f; //gardien dégagement latérale droit élevé GetComponent <Animation>()["goalkeeper_high_left"].speed = 1.0f; //gardien dégagement latérale gauche élevé GetComponent <Animation>()["goalkeeper_low_right"].speed = 1.0f; //gardien dégagement latérale droit plat GetComponent <Animation>()["goalkeeper_low_left"].speed = 1.0f; //gardien dégagement latérale gauche plat }
// to know if GoalKeeper is touching Ball void OnCollisionStay(Collision coll) { if (Camera.main.GetComponent <InGameState_Script>().state == InGameState_Script.InGameState.PLAYING) { if (coll.collider.transform.gameObject.tag == "Ball" && state != GoalKeeper_State.UP_WITH_BALL && state != GoalKeeper_State.PASS_HAND && state != GoalKeeper_State.THROW_GATE && state != GoalKeeper_State.JUMP_LEFT && state != GoalKeeper_State.JUMP_RIGHT && state != GoalKeeper_State.JUMP_LEFT_FLAT && state != GoalKeeper_State.JUMP_RIGHT_FLAT) { Camera.main.GetComponent <InGameState_Script>().lastTouched = gameObject; Vector3 relativePos = transform.InverseTransformPoint(sphere.gameObject.transform.position); // attraper le ballon sauf si l'altitude est inf a 0.35f (relative) if (relativePos.y < 0.35f) { sphere.owner = null; GetComponent <Animation>().Play("goalkeeper_front_guard"); state = GoalKeeper_State.GET_BALL_DOWN; } } } }
// To know if GoalKeeper is touching Ball void OnCollisionStay(Collision coll) { if (Camera.main.GetComponent <InGameState_Script>().state == InGameState_Script.InGameState.PLAYING) { if (coll.collider.transform.gameObject.tag == "Ball" && state != GoalKeeper_State.UP_WITH_BALL && state != GoalKeeper_State.PASS_HAND && state != GoalKeeper_State.GOAL_KICK && state != GoalKeeper_State.JUMP_LEFT && state != GoalKeeper_State.JUMP_RIGHT && state != GoalKeeper_State.JUMP_LEFT_DOWN && state != GoalKeeper_State.JUMP_RIGHT_DOWN) { Camera.main.GetComponent <InGameState_Script>().lastTouched = gameObject; Vector3 relativePos = transform.InverseTransformPoint(sphere.gameObject.transform.position); // only get ball if the altitude is 0.35f (relative) if (relativePos.y < 0.35f) { sphere.owner = null; GetComponent <Animation>().Play("goalkeeper_get_ball_front"); state = GoalKeeper_State.GET_BALL_DOWN; } } } }
// Update is called once per frame void Update() { /* This switch statement lets me control the goalkeepr state. */ switch (state) { /* This is the JUMP_RIGHT state. When triggered, I make the goalkeeper jump to the right, and I play the * "diveRight" animation. I also turn the capsule collider on the keepr to be horizontal so it stays inline * with his body. After that animation has played, and the keeper has dive, I change the state to be * MOVE_TO_RESTING, which then tells the keeper to move back to his initial position. */ case GoalKeeper_State.JUMP_RIGHT: capsuleCollider.direction = 0; //changes the collider to be horizontal when the keeper dives if (animation["playerDiveRight"].normalizedTime < 0.45f) { transform.position += transform.right * Time.deltaTime * 7.0f; } if (!animation.IsPlaying("playerDiveRight")) { state = GoalKeeper_State.MOVE_TO_RESTING; capsuleCollider.direction = 1; } break; /*This is the same concept as the state above */ case GoalKeeper_State.JUMP_LEFT: capsuleCollider.direction = 0; if (animation["playerDiveLeftLow"].normalizedTime < 0.45f) { transform.position -= transform.right * Time.deltaTime * 7.0f; } if (!animation.IsPlaying("playerDiveLeftLow")) { state = GoalKeeper_State.JUMP_LEFT; //resting capsuleCollider.direction = 1; /*For some reason after diving to the bottom left, the keeeper would not enter the MOVE_TO_RESTING * state where he walks back to his original starting position. I dont know why. To fix this, I created * a method called "ReturnToRestState" that automatically sets the keepers state to that state after he has dived * to the left. Its called via the StartCoroutine function below. It solved the issue */ StartCoroutine("ReturnToRestState"); } break; case GoalKeeper_State.JUMP_LEFT_HIGH: capsuleCollider.direction = 0; if (animation["playerDiveLeftHigh"].normalizedTime < 0.45f) { transform.position -= transform.right * Time.deltaTime * 4.0f; } if (!animation.IsPlaying("playerDiveLeftHigh")) { state = GoalKeeper_State.JUMP_LEFT; capsuleCollider.direction = 1; } break; case GoalKeeper_State.JUMP_RIGHT_HIGH: capsuleCollider.direction = 0; if (animation["playerDiveRightLow"].normalizedTime < 0.45f) { transform.position += transform.right * Time.deltaTime * 4.0f; } if (!animation.IsPlaying("playerDiveRightLow")) { state = GoalKeeper_State.MOVE_TO_RESTING; capsuleCollider.direction = 1; } break; /*This state is active just after the keepr has dived. After diving, he is now out of position and must * move back to his original standing position. After he has finished diving, the keeper moves to his * starting spot which is stored in the initial_Position variable. While doing so he always looks at the * player so if the player takes their next shot fast, the goalkeepers is ready to make a save. */ case GoalKeeper_State.MOVE_TO_RESTING: capsuleCollider.direction = 1; //Resets the capsule collider to be vertical if (!animation.IsPlaying("Move_Sideways")) { animation.Play("Move_Sideways"); } transform.LookAt(new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z)); //face the player transform.position = Vector3.MoveTowards(transform.position, initial_Position, Time.deltaTime); //move back to starting position /*Once the keeper reaches his starting position, he changes his state to RESTING as he doesnt need to move * any further */ if (Vector3.Distance(transform.position, initial_Position) < 0.2f) { state = GoalKeeper_State.RESTING; } break; /*THis is the goalkeeper idle state. He faces the player and stays still in this state. */ case GoalKeeper_State.RESTING: capsuleCollider.direction = 1; if (!animation.IsPlaying("playerIdle")) { animation.Play("playerIdle"); } transform.LookAt(new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z)); float distanceBall = (transform.position - sphere.transform.position).magnitude; if (distanceBall < 10.0f) { state = GoalKeeper_Script.GoalKeeper_State.RESTING; //come back to thus } break; } }
/*Sets the keepers state to MOVE_TO_RESTING */ IEnumerator ReturnToRestState() { yield return(new WaitForSeconds(0)); state = GoalKeeper_State.MOVE_TO_RESTING; }
// Update is called once per frame void Update() { //----------------------------------- //REQUERIDO PARA EL MOVIMIENTO DEL PORTERO stamina += 2.0f * Time.deltaTime; stamina = Mathf.Clamp(stamina, 1, 64); // sujeta un valor entre uno mínimo y otro maximo //----------------------------- switch (state) { case GoalKeeper_State.JUMP_LEFT: capsuleCollider.direction = 0; if (GetComponent <Animation>()["goalkeeper_clear_left_up"].normalizedTime < 0.45f) { transform.position -= transform.right * Time.deltaTime * 7.0f; GuardarPosicionesList(); } if (!GetComponent <Animation>().IsPlaying("goalkeeper_clear_left_up")) { state = GoalKeeper_State.STOLE_BALL; capsuleCollider.direction = 1; } break; case GoalKeeper_State.JUMP_RIGHT: capsuleCollider.direction = 0; if (GetComponent <Animation>()["goalkeeper_clear_right_up"].normalizedTime < 0.45f) { transform.position += transform.right * Time.deltaTime * 7.0f; GuardarPosicionesList(); } if (!GetComponent <Animation>().IsPlaying("goalkeeper_clear_right_up")) { state = GoalKeeper_State.STOLE_BALL; capsuleCollider.direction = 1; } break; case GoalKeeper_State.JUMP_LEFT_DOWN: capsuleCollider.direction = 0; if (GetComponent <Animation>()["goalkeeper_clear_left_down"].normalizedTime < 0.45f) { transform.position -= transform.right * Time.deltaTime * 4.0f; GuardarPosicionesList(); } if (!GetComponent <Animation>().IsPlaying("goalkeeper_clear_left_down")) { state = GoalKeeper_State.STOLE_BALL; capsuleCollider.direction = 1; } break; case GoalKeeper_State.JUMP_RIGHT_DOWN: capsuleCollider.direction = 0; if (GetComponent <Animation>()["goalkeeper_clear_right_down"].normalizedTime < 0.45f) { transform.position += transform.right * Time.deltaTime * 4.0f; GuardarPosicionesList(); } if (!GetComponent <Animation>().IsPlaying("goalkeeper_clear_right_down")) { state = GoalKeeper_State.STOLE_BALL; capsuleCollider.direction = 1; } break; case GoalKeeper_State.GOAL_KICK: break; case GoalKeeper_State.PASS_HAND: if (GetComponent <Animation>()["goalkeeper_throw_out"].normalizedTime < 0.65f && sphere.gameObject.GetComponent <Rigidbody>().isKinematic == true) { sphere.gameObject.transform.position = hand_bone.position; sphere.gameObject.transform.rotation = hand_bone.rotation; } if (GetComponent <Animation>()["goalkeeper_throw_out"].normalizedTime > 0.65f && sphere.gameObject.GetComponent <Rigidbody>().isKinematic == true) { sphere.gameObject.GetComponent <Rigidbody>().isKinematic = false; sphere.gameObject.GetComponent <Rigidbody>().AddForce(transform.forward * 5000.0f + new Vector3(0.0f, 1300.0f, 0.0f)); } if (!GetComponent <Animation>().IsPlaying("goalkeeper_throw_out") || !GetComponent <Animation>().IsPlaying("goalkeeper_throw_out")) { state = GoalKeeper_State.GO_ORIGIN; } break; case GoalKeeper_State.UP_WITH_BALL: //ARRIBA CON LA PELOTA sphere.codigo = 1.0f; if (!GetComponent <Animation>().IsPlaying("goalkeeper_catch_ball")) { sphere.gameObject.GetComponent <Rigidbody>().isKinematic = true; sphere.gameObject.transform.position = hand_bone.position; sphere.gameObject.transform.rotation = hand_bone.rotation; timeToSacar -= Time.deltaTime; if (timeToSacar < 0.0f) { timeToSacar = UnityEngine.Random.Range(2.0f, 5.0f); GetComponent <Animation>().Play("goalkeeper_throw_out"); state = GoalKeeper_State.PASS_HAND; } } else { sphere.gameObject.transform.position = hand_bone.position; sphere.gameObject.transform.rotation = hand_bone.rotation; /* * Vector3 relativeCenter = transform.InverseTransformPoint( centro_campo.position ); * if ( relativeCenter.x > 10 ) * transform.Rotate( 0, 10, 0); * else if ( relativeCenter.x < -10 ) * transform.Rotate( 0, -10, 0); */ transform.LookAt(centro_campo.position); } break; case GoalKeeper_State.GET_BALL_DOWN: //CONSEGUIR EL BALON sphere.gameObject.transform.position = hand_bone.position; sphere.gameObject.transform.rotation = hand_bone.rotation; if (!GetComponent <Animation>().IsPlaying("goalkeeper_get_ball_front")) { GetComponent <Animation>().Play("goalkeeper_catch_ball"); state = GoalKeeper_State.UP_WITH_BALL; } break; case GoalKeeper_State.RESTING: capsuleCollider.direction = 1; if (!GetComponent <Animation>().IsPlaying("goalkeeper_rest")) { GetComponent <Animation>().Play("goalkeeper_rest"); } transform.LookAt(new Vector3(sphere.gameObject.transform.position.x, transform.position.y, sphere.gameObject.transform.position.z)); float distanceBall = (transform.position - sphere.gameObject.transform.position).magnitude; if (distanceBall < 10.0f) { state = GoalKeeper_Script.GoalKeeper_State.STOLE_BALL; } break; case GoalKeeper_State.STOLE_BALL: //Bola robada GetComponent <Animation>().Play("running"); Vector3 RelativeWaypointPosition = transform.InverseTransformPoint(sphere.gameObject.transform.position); float inputSteer = RelativeWaypointPosition.x / RelativeWaypointPosition.magnitude; transform.Rotate(0, inputSteer * 10.0f, 0); transform.position += transform.forward * 6.0f * Time.deltaTime; GuardarPosicionesList(); if (RelativeWaypointPosition.magnitude < 1.0f) { //Estaba quitado********************************** //state = GoalKeeper_State.RESTING; } break; case GoalKeeper_State.GO_ORIGIN: GetComponent <Animation>().Play("running"); RelativeWaypointPosition = transform.InverseTransformPoint(initialPosition1); inputSteer = RelativeWaypointPosition.x / RelativeWaypointPosition.magnitude; transform.Rotate(0, inputSteer * 10.0f, 0); transform.position += transform.forward * 6.0f * Time.deltaTime; GuardarPosicionesList(); if (RelativeWaypointPosition.magnitude < 1.0f) { state = GoalKeeper_State.RESTING; } break; //--------------AGRUEGO case GoalKeeper_State.DESPLAZAR: // ESTE CASO ES PARA DESPLAZAR JUGADORES HASTA UNA POSICION FINAL float difMagnitud = (posicionFinal - transform.position).magnitude; //Saber distancia entre posicion final y actual if (difMagnitud > 0.35f) //SI la diferencia entre posicion final y la actal es mayor de 1.0f, ingrese aquí. { Vector3 relPos1 = transform.InverseTransformPoint(posicionFinal); inputSteer = relPos1.x / relPos1.magnitude; transform.Rotate(0, inputSteer * 20.0f, 0); GetComponent <Animation>().Play("running"); float staminaTemp4 = Mathf.Clamp((stamina / STAMINA_DIVIDER), STAMINA_MIN, STAMINA_MAX); transform.position += transform.forward * 4.5f * Time.deltaTime * staminaTemp4 * Speed; GuardarPosicionesList(); } else { // El jugador rota hasta quedar en direccion de la pelota y cambia animacion a // descanzar o "rest" transform.LookAt(sphere.transform); GetComponent <Animation>().Play("rest"); //BanderaPosicion=1; CambioEstado(); } break; case GoalKeeper_State.DESPLAZAR1: GetComponent <Animation>().Play("rest"); break; //-------------- } }
// Update is called once per frame void Update() { switch (state) { case GoalKeeper_State.JUMP_LEFT: capsuleCollider.direction = 0; if (GetComponent <Animation>()["goalkeeper_high_left"].normalizedTime < 0.45f) { transform.position -= transform.right * Time.deltaTime * 7.0f; } if (!GetComponent <Animation>().IsPlaying("goalkeeper_high_left")) { state = GoalKeeper_State.STOLE_BALL; capsuleCollider.direction = 1; } break; case GoalKeeper_State.JUMP_RIGHT: capsuleCollider.direction = 0; if (GetComponent <Animation>()["goalkeeper_high_right"].normalizedTime < 0.45f) { transform.position += transform.right * Time.deltaTime * 7.0f; } if (!GetComponent <Animation>().IsPlaying("goalkeeper_high_right")) { state = GoalKeeper_State.STOLE_BALL; capsuleCollider.direction = 1; } break; case GoalKeeper_State.JUMP_LEFT_FLAT: capsuleCollider.direction = 0; if (GetComponent <Animation>()["goalkeeper_low_left"].normalizedTime < 0.45f) { transform.position -= transform.right * Time.deltaTime * 4.0f; } if (!GetComponent <Animation>().IsPlaying("goalkeeper_low_left")) { state = GoalKeeper_State.STOLE_BALL; capsuleCollider.direction = 1; } break; case GoalKeeper_State.JUMP_RIGHT_FLAT: capsuleCollider.direction = 0; if (GetComponent <Animation>()["goalkeeper_low_right"].normalizedTime < 0.45f) { transform.position += transform.right * Time.deltaTime * 4.0f; } if (!GetComponent <Animation>().IsPlaying("goalkeeper_low_right")) { state = GoalKeeper_State.STOLE_BALL; capsuleCollider.direction = 1; } break; case GoalKeeper_State.THROW_GATE: break; case GoalKeeper_State.PASS_HAND: //gardien lance à main levé if (GetComponent <Animation>()["goalkeeper_serve_high_hand"].normalizedTime < 0.65f && sphere.gameObject.GetComponent <Rigidbody>().isKinematic == true) { sphere.gameObject.transform.position = hand_bone.position; sphere.gameObject.transform.rotation = hand_bone.rotation; } if (GetComponent <Animation>()["goalkeeper_serve_high_hand"].normalizedTime > 0.65f && sphere.gameObject.GetComponent <Rigidbody>().isKinematic == true) { sphere.gameObject.GetComponent <Rigidbody>().isKinematic = false; sphere.gameObject.GetComponent <Rigidbody>().AddForce(transform.forward * 5000.0f + new Vector3(0.0f, 1300.0f, 0.0f)); } if (!GetComponent <Animation>().IsPlaying("goalkeeper_serve_high_hand") || !GetComponent <Animation>().IsPlaying("goalkeeper_serve_high_hand")) { state = GoalKeeper_State.GO_ORIGIN; } break; case GoalKeeper_State.UP_WITH_BALL: if (!GetComponent <Animation>().IsPlaying("goalkeeper_lifts_ball")) { sphere.gameObject.GetComponent <Rigidbody>().isKinematic = true; sphere.gameObject.transform.position = hand_bone.position; sphere.gameObject.transform.rotation = hand_bone.rotation; timeToSacar -= Time.deltaTime; if (timeToSacar < 0.0f) { timeToSacar = UnityEngine.Random.Range(2.0f, 5.0f); GetComponent <Animation>().Play("goalkeeper_serve_high_hand"); state = GoalKeeper_State.PASS_HAND; } } else { sphere.gameObject.transform.position = hand_bone.position; sphere.gameObject.transform.rotation = hand_bone.rotation; transform.LookAt(center_field.position); } break; case GoalKeeper_State.GET_BALL_DOWN: sphere.gameObject.transform.position = hand_bone.position; sphere.gameObject.transform.rotation = hand_bone.rotation; //gardien arrete le ballon if (!GetComponent <Animation>().IsPlaying("goalkeeper_front_guard")) { GetComponent <Animation>().Play("goalkeeper_lifts_ball"); state = GoalKeeper_State.UP_WITH_BALL; } break; case GoalKeeper_State.RESTING: capsuleCollider.direction = 1; if (!GetComponent <Animation>().IsPlaying("guard")) { GetComponent <Animation>().Play("guard"); //gardien en repos } transform.LookAt(new Vector3(sphere.gameObject.transform.position.x, transform.position.y, sphere.gameObject.transform.position.z)); float distanceBall = (transform.position - sphere.gameObject.transform.position).magnitude; if (distanceBall < 10.0f) { state = GoalKeeper_Script.GoalKeeper_State.STOLE_BALL; } break; case GoalKeeper_State.STOLE_BALL: GetComponent <Animation>().Play("run"); //running Vector3 RelativeWaypointPosition = transform.InverseTransformPoint(sphere.gameObject.transform.position); float inputSteer = RelativeWaypointPosition.x / RelativeWaypointPosition.magnitude; transform.Rotate(0, inputSteer * 10.0f, 0); transform.position += transform.forward * 6.0f * Time.deltaTime; if (RelativeWaypointPosition.magnitude < 1.0f) { // state = GoalKeeper_State.RESTING; } break; case GoalKeeper_State.GO_ORIGIN: GetComponent <Animation>().Play("run"); RelativeWaypointPosition = transform.InverseTransformPoint(initial_Position); inputSteer = RelativeWaypointPosition.x / RelativeWaypointPosition.magnitude; transform.Rotate(0, inputSteer * 10.0f, 0); transform.position += transform.forward * 6.0f * Time.deltaTime; if (RelativeWaypointPosition.magnitude < 1.0f) { state = GoalKeeper_State.RESTING; } break; } }
// Update is called once per frame void Update() { switch (state) { case GoalKeeper_State.JUMP_LEFT: capsuleCollider.direction = 0; if (GetComponent <Animation>()["goalkeeper_clear_left_up"].normalizedTime < 0.45f) { transform.position -= transform.right * Time.deltaTime * 7.0f; } if (!GetComponent <Animation>().IsPlaying("goalkeeper_clear_left_up")) { state = GoalKeeper_State.STOLE_BALL; capsuleCollider.direction = 1; } break; case GoalKeeper_State.JUMP_RIGHT: capsuleCollider.direction = 0; if (GetComponent <Animation>()["goalkeeper_clear_right_up"].normalizedTime < 0.45f) { transform.position += transform.right * Time.deltaTime * 7.0f; } if (!GetComponent <Animation>().IsPlaying("goalkeeper_clear_right_up")) { state = GoalKeeper_State.STOLE_BALL; capsuleCollider.direction = 1; } break; case GoalKeeper_State.JUMP_LEFT_DOWN: capsuleCollider.direction = 0; if (GetComponent <Animation>()["goalkeeper_clear_left_down"].normalizedTime < 0.45f) { transform.position -= transform.right * Time.deltaTime * 4.0f; } if (!GetComponent <Animation>().IsPlaying("goalkeeper_clear_left_down")) { state = GoalKeeper_State.STOLE_BALL; capsuleCollider.direction = 1; } break; case GoalKeeper_State.JUMP_RIGHT_DOWN: capsuleCollider.direction = 0; if (GetComponent <Animation>()["goalkeeper_clear_right_down"].normalizedTime < 0.45f) { transform.position += transform.right * Time.deltaTime * 4.0f; } if (!GetComponent <Animation>().IsPlaying("goalkeeper_clear_right_down")) { state = GoalKeeper_State.STOLE_BALL; capsuleCollider.direction = 1; } break; case GoalKeeper_State.GOAL_KICK: break; case GoalKeeper_State.PASS_HAND: if (GetComponent <Animation>()["goalkeeper_throw_out"].normalizedTime < 0.65f && sphere.gameObject.GetComponent <Rigidbody>().isKinematic == true) { sphere.gameObject.transform.position = hand_bone.position; sphere.gameObject.transform.rotation = hand_bone.rotation; } if (GetComponent <Animation>()["goalkeeper_throw_out"].normalizedTime > 0.65f && sphere.gameObject.GetComponent <Rigidbody>().isKinematic == true) { sphere.gameObject.GetComponent <Rigidbody>().isKinematic = false; sphere.gameObject.GetComponent <Rigidbody>().AddForce(transform.forward * 5000.0f + new Vector3(0.0f, 1300.0f, 0.0f)); } if (!GetComponent <Animation>().IsPlaying("goalkeeper_throw_out") || !GetComponent <Animation>().IsPlaying("goalkeeper_throw_out")) { state = GoalKeeper_State.GO_ORIGIN; } break; case GoalKeeper_State.UP_WITH_BALL: if (!GetComponent <Animation>().IsPlaying("goalkeeper_catch_ball")) { sphere.gameObject.GetComponent <Rigidbody>().isKinematic = true; sphere.gameObject.transform.position = hand_bone.position; sphere.gameObject.transform.rotation = hand_bone.rotation; timeToSacar -= Time.deltaTime; if (timeToSacar < 0.0f) { timeToSacar = UnityEngine.Random.Range(2.0f, 5.0f); GetComponent <Animation>().Play("goalkeeper_throw_out"); state = GoalKeeper_State.PASS_HAND; } } else { sphere.gameObject.transform.position = hand_bone.position; sphere.gameObject.transform.rotation = hand_bone.rotation; /* * Vector3 relativeCenter = transform.InverseTransformPoint( centro_campo.position ); * if ( relativeCenter.x > 10 ) * transform.Rotate( 0, 10, 0); * else if ( relativeCenter.x < -10 ) * transform.Rotate( 0, -10, 0); */ transform.LookAt(centro_campo.position); } break; case GoalKeeper_State.GET_BALL_DOWN: sphere.gameObject.transform.position = hand_bone.position; sphere.gameObject.transform.rotation = hand_bone.rotation; if (!GetComponent <Animation>().IsPlaying("goalkeeper_get_ball_front")) { GetComponent <Animation>().Play("goalkeeper_catch_ball"); state = GoalKeeper_State.UP_WITH_BALL; } break; case GoalKeeper_State.RESTING: capsuleCollider.direction = 1; if (!GetComponent <Animation>().IsPlaying("goalkeeper_rest")) { GetComponent <Animation>().Play("goalkeeper_rest"); } transform.LookAt(new Vector3(sphere.gameObject.transform.position.x, transform.position.y, sphere.gameObject.transform.position.z)); float distanceBall = (transform.position - sphere.gameObject.transform.position).magnitude; if (distanceBall < 10.0f) { state = GoalKeeper_Script.GoalKeeper_State.STOLE_BALL; } break; case GoalKeeper_State.STOLE_BALL: GetComponent <Animation>().Play("running"); Vector3 RelativeWaypointPosition = transform.InverseTransformPoint(sphere.gameObject.transform.position); float inputSteer = RelativeWaypointPosition.x / RelativeWaypointPosition.magnitude; transform.Rotate(0, inputSteer * 10.0f, 0); transform.position += transform.forward * 6.0f * Time.deltaTime; if (RelativeWaypointPosition.magnitude < 1.0f) { // state = GoalKeeper_State.RESTING; } break; case GoalKeeper_State.GO_ORIGIN: GetComponent <Animation>().Play("running"); RelativeWaypointPosition = transform.InverseTransformPoint(initial_Position); inputSteer = RelativeWaypointPosition.x / RelativeWaypointPosition.magnitude; transform.Rotate(0, inputSteer * 10.0f, 0); transform.position += transform.forward * 6.0f * Time.deltaTime; if (RelativeWaypointPosition.magnitude < 1.0f) { state = GoalKeeper_State.RESTING; } break; } }