Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class LookAtMouse : MonoBehaviour
  5. {
  6.  
  7. // speed
  8. public float speed;
  9.  
  10. void FixedUpdate()
  11. {
  12. Plane playerPlane = new Plane(Vector3.up, transform.position);
  13.  
  14. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  15.  
  16. float hitdist = 0.0f;
  17.  
  18. if (playerPlane.Raycast(ray, out hitdist))
  19. {
  20. Vector3 targetPoint = ray.GetPoint(hitdist);
  21. Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position);.
  22. transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, speed * Time.deltaTime);
  23. }
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement