Hi,
My script is fully functional, but what i want to do is, instead of allowing my billboard to face camera by completely turning, i only want it to turn a maximum of 15 degrees left and right…
Like if i am in front of the plane, the angle of plane will be eith 90 or 180 or 360, what i want is it should maximum turn left or right to 15 degrees…
how can i achieve this ?
This is my script below -
using UnityEngine;
using System.Collections;
public class Billboard : MonoBehaviour
{
Camera referenceCamera;
public enum Axis {up, down, left, right, forward, back};
public bool reverseFace = false;
public Axis axis = Axis.up;
// return a direction based upon chosen axis
public Vector3 GetAxis (Axis refAxis)
{
switch (refAxis)
{
case Axis.down:
return Vector3.down;
case Axis.forward:
return Vector3.forward;
case Axis.back:
return Vector3.back;
case Axis.left:
return Vector3.left;
case Axis.right:
return Vector3.right;
}
// default is Vector3.up
return Vector3.up;
}
void Awake ()
{
// if no camera referenced, grab the main camera
if (!referenceCamera)
referenceCamera = Camera.main;
}
void Update ()
{
// rotates the object relative to the camera
Vector3 targetPos = transform.position + referenceCamera.transform.rotation * (reverseFace ? Vector3.forward : Vector3.back) ;
Vector3 targetOrientation = referenceCamera.transform.rotation * GetAxis(axis);
transform.LookAt (targetPos, targetOrientation);
}
}
I mean i dont want this to happen
I want it to turn max 15 degrees both sides from its base angle and only in the X - AXIS