- Home /
Trouble making Dynamic Billboard
I'm a long time trying to make a dynamic billboard script. I need to control the different axes billboard blocking do not want to be billboard but not equaling zero, but retain the original rotation of that axis. I searched many forums without finding an answer. I have studied the Quaternion system, and I managed to handle it but only on one axis and not two, and always having to carry zero axes do not want to be modified. There is some information that I'm driving or something I'm doing wrong.
I hope someone can help me, thanks
Answer by ScroodgeM · Aug 21, 2012 at 08:50 PM
using UnityEngine; using System.Collections; public class BillboardOrienter : MonoBehaviour { public Transform target; private Vector3 myUpDirection; void Start() { myUpDirecton = transform.up; } void Update() { Vector3 relativePos = optionalTarget.position - transform.position; Quaternion rotation = Quaternion.LookRotation(relativePos, myUpDirecton); transform.rotation = rotation; } }
Scroodge, thank you for your quick response. The reply code already knew, what I need is to make a two-axis rotation. For example the x and y axis look at the camera and keep your angle z axis.
X and Y axis look at the camera? i can't imagine it 8) please explain 8)
Sorry, you're right, what I meant is that for example the z axis is facing the camera, the angles X and Y rotate but the angle z is fixed at a certain angle. thanks
second parameter in Quaternion.LookRotation method is created to point the 'up' direction. this lets you keep Y-axis on rotated object to be as close as possible to 'up' using rotating around Z-axis. methinks this is what you need.
var relativePos=optionalTarget.position-transform.position;
transform.rotation=Quaternion.LookRotation(relativePos,Vector3.forward);
is the closest thing I need but the Z axis is fixed at zero. If the object has an original rotation on the z axis, when I applied the script modifies the z axis rotation and makes it as if the angle is zero.
Your answer
Follow this Question
Related Questions
Use Iphone as sterring wheel 2 Answers
Billboard script 1 Answer
Can you help me sort out my script and collision? 1 Answer
How to set rotation.y to predefined angles. 3 Answers
Third Person Camera Orbit 0 Answers