public void GetInBed() { Vector3 lookAt = Vector3.zero; switch (getinBedAnimation) { //Stage 1 case GetinBedAnimation.Move: //Toggle walking animation toggleWalkAnimation(true); //MoveTowards transform.position = Vector3.MoveTowards(transform.position, new Vector3(-330, 0, -25), walkingSpeed * Time.deltaTime); //Look at the position to walk to lookAt = new Vector3(-340, 0, -25) - transform.position; lookAt.y = 0; if (Vector3.Angle(transform.forward, new Vector3(-340, 0, -25) - new Vector3(transform.position.x, 0, transform.position.y)) > 1f) { halfStanding = true; getOutBedAnimation = GetOutBedAnimation.Move; var lookRotation = Quaternion.LookRotation(lookAt); transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, 5 * Time.deltaTime); } //If i've reached the position if (transform.localPosition.x == -330f && transform.localPosition.z == -25f) { getOutBedAnimation = GetOutBedAnimation.Move; getinBedAnimation = GetinBedAnimation.FaceScreen; } break; //Stage 2 case GetinBedAnimation.FaceScreen: //Toggle walking animation toggleWalkAnimation(true); //Look at the position to walk to lookAt = new Vector3(-330, 0, -100) - transform.position; lookAt.y = 0; if (Vector3.Angle(transform.forward, new Vector3(-330, 0, -100) - new Vector3(transform.position.x, 0, transform.position.y)) > 1f) { halfStanding = true; getOutBedAnimation = GetOutBedAnimation.Move; var lookRotation = Quaternion.LookRotation(lookAt); transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, 5 * Time.deltaTime); } //Looking towards the screen else { getOutBedAnimation = GetOutBedAnimation.Move; getinBedAnimation = GetinBedAnimation.GoUp; } break; //Stage 3 case GetinBedAnimation.GoUp: //Make sure the player isn't walking toggleWalkAnimation(false); if (bed.transform.position.y < -14) { getOutBedAnimation = GetOutBedAnimation.MoveDown; halfStanding = true; bed.transform.position = (new Vector3(bed.transform.position.x, (bed.transform.position.y + (30 * Time.deltaTime)), bed.transform.position.z)); } else { bed.transform.position = new Vector3(bed.transform.position.x, -13.1f, bed.transform.position.z); } if (player.transform.position.y < 50) { getOutBedAnimation = GetOutBedAnimation.MoveDown; halfStanding = true; player.transform.Translate(new Vector3(0, 30 * Time.deltaTime, 0), Space.World); } else { player.transform.localPosition = new Vector3(-330, 50, -25); } if ((bed.transform.position.y < -13.0f && bed.transform.position.y > -13.2f) && (player.transform.position.y <= 50 && player.transform.position.y >= 50)) { getOutBedAnimation = GetOutBedAnimation.MoveDown; getinBedAnimation = GetinBedAnimation.LieDown; } break; //Stage 4 case GetinBedAnimation.LieDown: //Make sure the player isn't walking toggleWalkAnimation(false); if (player.transform.rotation.eulerAngles.x > 313 || player.transform.rotation.eulerAngles.x < 311) { halfStanding = true; getOutBedAnimation = GetOutBedAnimation.StandUp; player.transform.Rotate(10.0f * Time.deltaTime * animationSpeed, 0.0f, 0.0f, Space.World); } else { float y = player.transform.eulerAngles.y; float z = player.transform.eulerAngles.z; player.transform.eulerAngles = new Vector3(-48, y, z); //set standing and reset to starting action halfStanding = false; standing = false; getOutBedAnimation = GetOutBedAnimation.StandUp; } break; } }
public void GetOutOfBed() { Vector3 lookAt = new Vector3(); switch (getOutBedAnimation) { //Stage 1 case GetOutBedAnimation.StandUp: //Make sure the player isn't walking toggleWalkAnimation(false); //Rotate the player so that they're standing up. if (player.transform.rotation.eulerAngles.x > 1 && player.transform.rotation.eulerAngles.x < 359) { //The player has executed the standing procedure halfStanding = true; player.transform.Rotate(-5.0f * Time.deltaTime * animationSpeed, 0.0f, 0.0f, Space.World); getinBedAnimation = GetinBedAnimation.LieDown; } else { //The player is not standing up float y = player.transform.eulerAngles.y; float z = player.transform.eulerAngles.z; player.transform.eulerAngles = new Vector3(0, y, z); getOutBedAnimation = GetOutBedAnimation.MoveDown; getinBedAnimation = GetinBedAnimation.LieDown; } break; //Stage 2 case GetOutBedAnimation.MoveDown: //Make sure the player isn't walking toggleWalkAnimation(false); //Move the bed down if (bed.transform.position.y > -63.1) { getinBedAnimation = GetinBedAnimation.GoUp; halfStanding = true; bed.transform.position = (new Vector3(bed.transform.position.x, (bed.transform.position.y + (-30 * Time.deltaTime)), bed.transform.position.z)); } else { bed.transform.position = new Vector3(bed.transform.position.x, -63.1f, bed.transform.position.z); } //Move the player down if (player.transform.position.y > 0) { getinBedAnimation = GetinBedAnimation.GoUp; halfStanding = true; player.transform.Translate(new Vector3(0, -30 * Time.deltaTime, 0), Space.World); } else { player.transform.localPosition = new Vector3(-330, 0, -25); } if ((bed.transform.position.y >= -63.1f && bed.transform.position.y <= -63.1f) && (player.transform.position.y >= 0 && player.transform.position.y <= 0)) { getinBedAnimation = GetinBedAnimation.GoUp; getOutBedAnimation = GetOutBedAnimation.Move; } break; case GetOutBedAnimation.Move: //Toggle walking animation toggleWalkAnimation(true); //MoveTowards transform.position = Vector3.MoveTowards(transform.position, new Vector3(-210, 0, -25), walkingSpeed * Time.deltaTime); //Look at the position to walk to lookAt = new Vector3(-200, 0, -25) - transform.position; lookAt.y = 0; if (Vector3.Angle(transform.forward, new Vector3(-200, 0, -25) - new Vector3(transform.position.x, 0, transform.position.y)) > 1f) { getinBedAnimation = GetinBedAnimation.Move; halfStanding = true; var lookRotation = Quaternion.LookRotation(lookAt); transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, 5 * Time.deltaTime); } //If i've reached the position if (transform.localPosition.x == -210f && transform.localPosition.z == -25f) { getinBedAnimation = GetinBedAnimation.Move; getOutBedAnimation = GetOutBedAnimation.FaceScreen; } break; case GetOutBedAnimation.FaceScreen: //Toggle walking animation toggleWalkAnimation(true); //Look at the position to walk to lookAt = new Vector3(-210, 0, -100) - this.transform.position; lookAt.y = 0; if (Vector3.Angle(transform.forward, new Vector3(-210, 0, -100) - new Vector3(transform.position.x, 0, transform.position.y)) > 1f) { halfStanding = true; getinBedAnimation = GetinBedAnimation.Move; var lookRotation = Quaternion.LookRotation(lookAt); transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, 5 * Time.deltaTime); } //Looking towards the screen else { getinBedAnimation = GetinBedAnimation.Move; toggleWalkAnimation(false); standing = true; halfStanding = false; } break; } }