Hi every one.
I just loocking to optimize my code.
The give code use rotate camera around specfic target(Gameobject) so when target rotate about x or y axis but not z-axis the camera also rotate.
The code work very well but is there any way to optimize expression in line 21 so I don’t want to use Quaternion.Euler and target.eulerAngles I just want to use any other Quaternion operation and target.rotation to get to same result
using UnityEngine;
using System.Collections;
public class cam : MonoBehaviour
{
public Transform target;
public float s, sd;
Transform t;
Vector2 delta_ang = new Vector2 (0f, 0f);
float d = 0;
void Start ()
{
t = GetComponent<Transform> ();
}
void LateUpdate ()
{
if (Input.GetMouseButton (0))
delta_ang.x += s * Input.GetAxis ("Mouse Y");
if (Input.GetMouseButton (1))
delta_ang.y -= s * Input.GetAxis ("Mouse X");
d = Mathf.Clamp (d - sd * Input.GetAxis ("Mouse ScrollWheel"), 7f, 20f);
Quaternion ang = Quaternion.Euler (target.eulerAngles.x + delta_ang.x, target.eulerAngles.y + delta_ang.y, 0);
t.position = target.position + ang * Vector3.back * d;
t.rotation = ang;
}
}