Question by
Mihanano · Aug 02, 2016 at 09:06 PM ·
c#servereuleranglesmouselook
Quaternion rotation to mouse look
Greeting to all :)
I would like to get some help on a script to rotate an objects y-axis around the z-axis . The y-axis is looking at the mouse from a ray that is being cast from the camera to a plane (orthographic)
using UnityEngine; using System.Collections;
public class turretRotation : MonoBehaviour {
Camera viewCamera;
void Start () {
viewCamera = Camera.main;
}
// Update is called once per frame
void Update () {
Ray ray = viewCamera.ScreenPointToRay(Input.mousePosition);
Plane backroundPlane = new Plane(Vector3.back, Vector3.zero);
float rayDistance;
if(backroundPlane.Raycast(ray,out rayDistance))
{
Vector3 point = ray.GetPoint(rayDistance);
//Debug.DrawLine(ray.origin, point, Color.yellow);
LookAt(point);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
[C#]detect object on mouse look? 1 Answer
500 Internal server error in WWWForm 0 Answers
How Do I Clamp A Rotation? 0 Answers
How to disable the camera's movement when the game is paused? 2 Answers