Hello Everybody,
I use this script for my space game project.But i have a problem.I need your helps.
Problem : My ship always looking the mouse position.I dont want this.I want when im clickin mouse button 1 , my ship must rotate and go where im clicked , smootly.
Thanks.
public class PlayerMovement : MonoBehaviour
{
public float movementSpeed;
public GameObject camera;
void Update()
{
Plane playerPlane = new Plane(Vector3.up, transform.position);
Ray ray = UnityEngine.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);
targetRotation.x = 0;
targetRotation.z = 0;
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 7f * Time.deltaTime);
}
if (Input.GetKey(KeyCode.Mouse0))
transform.Translate(Vector3.forward * movementSpeed * Time.deltaTime);
}
}