# Video provided-Rotate 2d character in 3d world

video link [Help- How to rotate a 2d character in 3d world? - YouTube][1]

Hello. I am trying to rotate a 2d plane relative to the camera depending on the cam’s position & rotation to it.

the 2d plan is a character in a 3d world. Of course when the cam comes to or is at the left/right of the plane, the plan will seem to disappear. I am trying to get the character plane to rotate at least 30 degrees at that point towards the left/right depending on the cam position, so it will never ‘disappear’.

the closest i came to this was in this attempt

``````    var checks : float[];
var myRots : float[];

if(Mathf.Clamp(cam.transform.eulerAngles.y, checks_-5, checks *+ 25) == cam.transform.eulerAngles.y)*_
``````

transform.localEulerAngles.y = transform.parent.transform.rotation.y * myRots*;*
Here i manually input camera rotations into the checks string, and when the cam rotation is that rotation, i tell the character to rotate itself accordingly.
this only works until the character itself rotates, then the everything i set becomes incorrect. The character is in an empty gameObject. I rotate the parent obj when moving in the world, and rotate the actual plan as needed for the camera.
Please give an example when explaining- I am horrible at rotations! Thanks
_*[1]: Help- How to rotate a 2d character in 3d world? - YouTube

While I believe I understand your problem, without more of your code and an understanding of the app, I’m unsure of the best fix. Here is my suggestion. I’m assuming you are using Unity’s Plane when you write ‘plane’. Instead, use a Unity Quad. The geometry is simpler, and it ‘faces’ the camera by default.

Each frame you get the Vector3.Angle() between the camera forward and the Quad forward. If they greater than 90, then the Quad cannot be seen. So for your 30 degrees check, you would use 60 degrees. If the angle is greater than 60 degrees, then apply the same rotation to the Quad you did to the camera. Untested, but something like this would work:

``````#pragma strict

var prevCamForward : Vector3;
var camTrans : Transform;
var qPrev : Quaternion;

function Start() {
camTrans = camera.main.transform;
prevCamForward = camTrans.forward;
qPrev = camTrans.rotation;
}

function LateUpdate() {
if (prevCamForward != camTrans.forward) {
if (Vector3.Angle(transform.forward, camTrans.forward) > 60.0) {
transform.rotation = camTrans.rotation * Quaternion.Inverse(qPrev) * transform.rotation;
}
}
prevCamForward = camTrans.forward;
qPrev = camTrans.rotation;
}
``````