void Update() { if (playerControl.m_FacingRight) { Vector3 pos = Camera.main.WorldToScreenPoint(transform.position); dir = Input.mousePosition - pos; var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); if (angle > 90 || angle < -90) { playerControl.Flip(); } } else if (!playerControl.m_FacingRight) { Vector3 pos = Camera.main.WorldToScreenPoint(transform.position); dir = -Input.mousePosition + pos; var angle = -Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); if (angle > 90 || angle < -90) { playerControl.Flip(); } } }
void Update() { // Rotate the vision cone if the game isn't paused if (Time.timeScale > 0) { Vector3 pos = Camera.main.WorldToScreenPoint(transform.position); Vector3 dir = Input.mousePosition - pos; float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); if (Math.Abs(angle) > 90) { if (playerScript.m_FacingRight) { playerScript.Flip(); } } else { if (!playerScript.m_FacingRight) { playerScript.Flip(); } } // Powerups pickup if (powerUp != null) { powerupCooldown += Time.deltaTime; //print(powerupCooldown); if (powerupCooldown >= powerUpPickupTime) { powerUp.GetComponent <PowerUp>().Collect(this.transform.parent.gameObject); powerUp = null; powerupCooldown = 0; } } // Antag lost if (!AntagFocused) { antagLostCooldown += Time.deltaTime; if (antagLostCooldown >= targetLostMaxTime) { playerScript.GetComponent <PlayerScript>().Die("You lost track of your target for too long."); } } else { antagLostCooldown = 0; } } }
void FixedUpdate() { // print (transform.localPosition.x+ ", " +transform.localPosition.y); if (isClimbing) // If climbing, move based on inputs and via local scale of the object you are connected { // This transform does it based on global direction (thus moving "up" will cause the player to move upwards on the scrren wile climbing the object) if (vineHorizontalSpeed > 0 && !PlayerScript.facingRight) // Flip the characters sprite if needed { PlayerScript.Flip(); } else if (vineHorizontalSpeed < 0 && PlayerScript.facingRight) { PlayerScript.Flip(); } if (Mathf.Abs(vineHorizontalSpeed) > 0) // If climbing horizontally { PlayerScript.Check_Wall(); if (!PlayerScript.hitWall) { if (HclimbingSpeed * Time.deltaTime > PlayerScript.distanceToWall) { transform.position += new Vector3(vineHorizontalSpeed * PlayerScript.distanceToWall, 0); } else { transform.position += new Vector3(vineHorizontalSpeed * HclimbingSpeed * Time.deltaTime, 0); } } } if (vineVerticalSpeed > 0) // If climbing up { PlayerScript.Check_Ceiling(); if (!PlayerScript.hitCeiling) { if (VclimbingSpeed * Time.deltaTime > PlayerScript.distanceToCeiling) { transform.position += new Vector3(0, PlayerScript.distanceToCeiling); } else { transform.position += new Vector3(0, vineVerticalSpeed * VclimbingSpeed * Time.deltaTime); } } } else // If climbing down // if(vineVerticalSpeed < 0) { PlayerScript.Check_Ground(); if (!PlayerScript.onGround) { if (VclimbingSpeed * Time.deltaTime > PlayerScript.distanceToGround) { transform.position -= new Vector3(0, PlayerScript.distanceToGround); } else { transform.position += new Vector3(0, vineVerticalSpeed * VclimbingSpeed * Time.deltaTime); } } } anim.SetFloat("verticalSpeed", Mathf.Abs(vineVerticalSpeed)); anim.SetFloat("horizontalSpeed", Mathf.Abs(vineHorizontalSpeed)); } if (anim != null) { anim.SetBool("Climbing", isClimbing); } }