Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class LookAtMouse : MonoBehaviour
- {
- // speed
- public float speed;
- void FixedUpdate()
- {
- 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, speed * Time.deltaTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement