Exemplo n.º 1
0
        public void LookAtTransform(Transform transf, Vector3 source, float dist, float hRot, float vRot)
        {
            PosRot look = LookAt(source, dist, hRot, vRot);

            transf.position = look.position;
            transf.rotation = look.rotation;
        }
Exemplo n.º 2
0
        PosRot LookAt(Vector3 source, float dist, float hRot, float vRot)
        {
            Vector3 norm = new Vector3(0f, 0f, 1f);

            norm = RotAround(vRot, norm, new Vector3(1f, 0f, 0f));
            norm = RotAround(hRot, norm, new Vector3(0f, 1f, 0f));

            norm = norm.normalized;

            Vector3    finalPos = source - dist * norm;
            Quaternion finalRot = Quaternion.Euler(-vRot, -hRot, 0f);

            PosRot pr = new PosRot
            {
                position = finalPos,
                rotation = finalRot
            };

            return(pr);
        }