Hello Unity3D i have a question about my camera.How can i code my camera to rotate to look at my player from a 2D view whenever i hit something or someone?Something like a 90 degree angle and when i run back or forward its back to a 3d view?If anyone knows how i can do this.Can you please tell me how this could be done?For some reason i can’t find it.
you can set a quaternion variable that is a 2d rotation relative to the player i.e. based on, var = player position(x,y,z-10), that you want for all the collisions in 2d, and use slerp to rotate the camera to that rotation in a time given, and then slerp back to the 3d view when you want, and the switch off the slerp function when it’s back in 3d. all it would need is
rotation = slerp(2drot,3drot,value from 0 to 1 to choose which rot);
that will only change the rotation of the camera correctly,
to also change it’s position in an arc around the player, you can place an invisible dot behind the camera, and then you can do
camera.transform.position = player position + (camerapos-invisibledotpos)*distance
or even
camera.transform.position = playerpos-camera.transform.forward*distancevar;
that will place the camera always facing the player whatever rotation it is at, at the same distance.
Sorry This is The Script If anyone is still interested
#pragma strict
var targetPos : Transform;
var lookAtObj : Transform;
// smooth damp stuff
private var targetVX : float;
private var targetVY : float;
private var targetVZ : float;
var targetSmoothDamp : float = 0.3;
var targets: GameObject[];
targets = gameObject.FindGameObjectsWithTag("Player");
function Start () {
}
function Update () {
transform.position.x = Mathf.SmoothDamp(transform.position.x, targetPos.position.x, targetVX, targetSmoothDamp);
transform.position.y = Mathf.SmoothDamp(transform.position.y, targetPos.position.y, targetVY, targetSmoothDamp);
transform.position.z = Mathf.SmoothDamp(transform.position.z, targetPos.position.z, targetVZ, targetSmoothDamp);
transform.LookAt(lookAtObj);
}