- Home /
Problem with Look at mouse in a spherical world
Hi!
I'm creating a game where the world is a big sphere and where the player can rotate around(like super mario galaxy) but, for the orientation of the player, I want to use the mouse, so I take a "Look at the mouse" script, but when the player arrive at something like half the world/sphere he start to stop following the mouse, turn where he want, when he want.
here's my code:
using UnityEngine;
using System.Collections;
public class PlayerLookAt : MonoBehaviour {
void Update ()
{
Plane playerPlane = new Plane(Vector3.up, transform.position);
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
float hitdist = 0.0f;
if (playerPlane.Raycast (ray, out hitdist))
{
Vector3 targetPoint = ray.GetPoint(hitdist);
Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, GetComponent<PlayerManager>().RotateSpeed * Time.deltaTime);
}
}
}
can you help me please.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612050141im_/https://answers.unity.com/themes/thub/images/avi.jpg)