Greetings, I am using a simple script to always have my 2d characters face the camera, however my camera is isometric and in 3d, and my characters tilt on the x-axis when I am walking near them making them appear to be falling over or go into walls etc (all around ugly effect),
is there a way to only make it so the characters will rotate but never tip over or tilt?
here is my script I am using"
camerafacingbillboard.cs
using UnityEngine;
using System.Collections;
public class CameraFacingBillboard : MonoBehaviour
{
public Camera m_Camera;
void Update()
{
transform.LookAt(transform.position + m_Camera.transform.rotation * Vector3.back,
m_Camera.transform.rotation * Vector3.up);
}
}
thanks in advance for your help
4 Answers
4
There might be a more elegant way but what about resetting the x axis value after the call to LookAt?
Set the ‘Y’ position of the point to look at to the same ‘Y’ as your character before calling LookAt (this assumes standard setup with camera looking down Z axis):
For example (untested):
Vector3 v3T = transform.position + m_Camera.transform.rotation * Vector3.back;
v3T.y = transform.position.y;
transform.LookAt(v3T, Vector3.up);
In a 3D game, LookAt doesn’t really work for billboarding well - you actually want to set the Y rotation to make a billboard’s forward be the inverse of the camera’s forward.
The problem is that the camera is a point in 3d space, but it’s view is a plane. Using LookAt will always cause the objects to rotate strangely when you get close to them (because they are looking at the camera and not the plane). The following will fix that on Y only. In Isometric LookAt might just work…
var cameraForwardForOrient = Quaternion.LookRotation(-CameraMain.transform.forward).eulerAngles;
cameraForwardForOrient = Quaternion.Euler(0,cameraForwardForOrient.y,0);
Thanks so much for your replies, But I am by no means a coder, so I wouldn’t know how to implement your answers into a usable format,
so, How would I do this in my code?
var cameraForwardForOrient = Quaternion.LookRotation(-CameraMain.transform.forward).eulerAngles;
cameraForwardForOrient = Quaternion.Euler(0,cameraForwardForOrient.y,0);
sorry for my ignorance, but you know what they say “ignorance is bliss” and I guess I am a very happy person. 
I wrote an article on rotations that might help with this on Unity Gems
– whydoidoit