World Rotation Around The Player Lead me to a Strange Result!
I want to rotate the world around the player position. Since I wanted this rotation to be not instant, nor controlled by time, neither based on duration of pressing a button, I used Animation Window. I am rotating the world to right when the player presses right. Because I wanted the world to rotate around the player, I created an empty game object and put the world into it and made it a child of the world to have a pivot point. As long as the world has not been rotated to any direction, world pivot works fine. If the world rotates to the right by 90 degree, the x and y of the pivot points turns out to be the opposite of y and x of the player position. I am changing those values for the world, but this time, pivot and the world acting very strange. When I am changing the player to right, the world moves a little bit in up direction.
Since it is an Uni project, I will appreciate any help. I am in need of urgent help. Note: The script below is attached to the player.
void Update()
{
RotateWorldAroundPivot();
CheckForGrounded();
Movement();
StartCoroutine(playerFreeze());
Jump();
StartCoroutine(WorldRotation());
Fall();
}
IEnumerator playerFreeze()
{
if (rigidBody2D.velocity.y > 1)
{
yield return new WaitForSecondsRealtime(0.8f);
Time.timeScale = 0.0001f;
canRotatetheWorld = true;
yield return new WaitForSecondsRealtime(2.5f);
Time.timeScale = 1f;
canRotatetheWorld = false;
}
}
IEnumerator WorldRotation()
{
if (canRotatetheWorld == true)
{
if (angleStatus == "zero" && Input.GetKeyUp("right"))
{
worldAnimator.SetInteger("WorldRotationAnim", 1);
yield return new WaitForSecondsRealtime(0.1f);
angleStatus = "nintyDegree";
}
if (angleStatus == "nintyDegree" && Input.GetKeyUp("right"))
{
worldAnimator.SetInteger("WorldRotationAnim", 2);
yield return new WaitForSecondsRealtime(0.1f);
angleStatus = "hundredEightyDegree";
}
if (angleStatus == "hundredEightyDegree" && Input.GetKeyUp("right"))
{
worldAnimator.SetInteger("WorldRotationAnim", 3);
yield return new WaitForSecondsRealtime(0.1f);
angleStatus = "minusNintyDegree";
}
if (angleStatus == "minusNintyDegree" && Input.GetKeyUp("right"))
{
worldAnimator.SetInteger("WorldRotationAnim", 4);
yield return new WaitForSecondsRealtime(0.1f);
angleStatus = "zero";
}
if (angleStatus == "nintyDegree" && Input.GetKeyUp("left"))
{
worldAnimator.SetInteger("WorldRotationAnim", -1);
yield return new WaitForSecondsRealtime(0.1f);
angleStatus = "zero";
}
if (angleStatus == "hundredEightyDegree" && Input.GetKeyUp("left"))
{
worldAnimator.SetInteger("WorldRotationAnim", -2);
yield return new WaitForSecondsRealtime(0.1f);
angleStatus = "nintyDegree";
}
if (angleStatus == "minusNintyDegree" && Input.GetKeyUp("left"))
{
worldAnimator.SetInteger("WorldRotationAnim", -3);
yield return new WaitForSecondsRealtime(0.1f);
angleStatus = "hundredEightyDegree";
}
if (angleStatus == "zero" && Input.GetKeyUp("left"))
{
worldAnimator.SetInteger("WorldRotationAnim", -4);
yield return new WaitForSecondsRealtime(0.1f);
angleStatus = "minusNintyDegree";
}
}
}
void RotateWorldAroundPivot()
{
if (angleStatus == "zero")
{
worldToRotate.transform.position = new Vector2(transform.position.x, transform.position.y);
worldPivot.transform.position = new Vector2(-transform.position.x, -transform.position.y);
}
if (angleStatus == "nintyDegree")
{
worldToRotate.transform.position = new Vector2(transform.position.x, transform.position.y);
worldPivot.transform.position = new Vector2(transform.position.y, -transform.position.x);
}
}
Your answer
Follow this Question
Related Questions
Camera Rotation Around Player 1 Answer
Camera not rotating alongside player character after new script. 0 Answers
Character Shooting Mechanic 2D Issues 0 Answers
TopDown Look at mouse 0 Answers