- Home /
CameraFacingBillboard with offset?
Hey i want to Usa a sprite as a Billboard to my Camera but with a slight offset. the code looks like this at the moment:
using UnityEngine;
using System.Collections;
public class CameraFacingBillboard : MonoBehaviour
{
public Camera m_Camera;
void Update()
{
transform.LookAt(transform.position + m_Camera.transform.rotation * Vector3.forward,
m_Camera.transform.rotation * Vector3.up);
}
}
that leads to the behavior, that the billboard is facing straight to the camera, but i want to have, lets say 10° more on the X and Z axis. so that the billboard is a little bit out of angle, how can i achieve this?
Answer by JoshDangIt · Oct 27, 2015 at 08:37 PM
So you want the billboard to face the camera with an offset? Try this (Untested):
public Vector3 offset;
void Update()
{
Vector3 camPos = Camera.main.transform.position;
Vector3 directionToLookAt = camPos - transform.position;
Quaternion rot = Quaternion.LookRotation (directionToLookAt);
Vector3 euler = rot.eulerAngles;
euler = euler + offset; //apply offset to euler
transform.eulerAngles = euler;
}
exactly what i wanted to do, thanks! :) but wait. now the billboard is flipped horizontal :D
Is this your problem? http://answers.unity3d.com/questions/41304/change-facing-direction.html
Your answer
Follow this Question
Related Questions
2D game Animation export VS Animation sprites. 1 Answer
Is there a way to set a sprite's color solid white? 4 Answers
Does Unity 2D tools generate atlas? 1 Answer
How to call sprite at run time 3 Answers