Planet rotation with player issue,[Q] Walking on a planet (rotation) while player is still
Hello, I am struggling with planet rotation on a single point.
Basically, I have a player who can run around a world (by this I mean the player is stationary at the top of the world and turns when the player uses the WASD or arrows keys) and I want to make it as if the player is running around the world by rotating the world as the player turns (see images).
My issue is that when I rotate the planet forward and back, and the same with left and right, but as soon as I do some forward/back and then some left/right (or vice versa) the planet rotates making it look like the controls are inverted (running backwards when forwards etc).
Is there any way to lock the rotation or maybe continue the rotation of the planet as the issue occurs when the rotation meet -360/360 and then goes back to 0 (this may or may not be the issue but it's a thought)
Issue example
public class PlanetController : MonoBehaviour
{
public float rotateSpeed = 40f;
private bool rotate = false;
private float x;
private float z;
float desiredRotX;
float desiredRotZ;
float damping = 10;
private void Start()
{
desiredRotX = transform.eulerAngles.x;
desiredRotZ = transform.eulerAngles.z;
}
private void Update()
{
if (rotate)
{
if (x>0)
{
desiredRotX += rotateSpeed * Time.deltaTime;
}
else if (x<0)
{
desiredRotX -= rotateSpeed * Time.deltaTime;
}
else if (z>0)
{
desiredRotZ -= rotateSpeed * Time.deltaTime;
}
else if (z < 0)
{
desiredRotZ += rotateSpeed * Time.deltaTime;
}
var desiredRotQ = Quaternion.Euler(desiredRotZ, transform.eulerAngles.y, desiredRotX);
transform.rotation = Quaternion.Lerp(transform.rotation, desiredRotQ, Time.deltaTime * damping);
}
else
{
this.x = 0;
this.z = 0;
}
}
//Function called from other script (playercontroller) with input hor/vert
public void RotateWorld(float x, float z)
{
rotate = true;
this.x = x;
this.z = z;
}
public void StopRotateWorld()
{
rotate = false;
}
}
Any ideas are welcome. Thanks
Holding S (down) When I hold it down, after some time it starts glitching out.
Your answer
Follow this Question
Related Questions
Check rotation of an obstacle 0 Answers
Rotate Player w/Touch Input Controls 0 Answers
the character refuses to rotate even in the editor 0 Answers
How to rotate an object according to the camera's view? 1 Answer
rotation problems 0 Answers