I have a spherical world which a player walks on. The player is rotated towards the mouse. This works fine when you first spawn and walk a bit, but once you are about halfway to the other side, the player looks in the wrong direction. Any ideas?
void Update() {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100))
Debug.DrawLine(ray.origin, hit.point);
Vector3 pos = hit.point;
float distanceToPlane = Vector3.Dot(transform.up, pos - transform.position);
Vector3 planePoint = pos - transform.up * distanceToPlane;
holder.LookAt(planePoint, transform.up);
}
void LateUpdate() {
spine.localEulerAngles = new Vector3(360-holder.rotation.eulerAngles.y,0f,0f);
}
Just a little note, on the LateUpdate function, I put a “360-”, if I removed that, then my situation would be flipped. So, the rotating on the other side of the planet would work, but not on the side I spawn on.