- Home /
Point FPC camera at object after repositioning.
Hi,
Within my project I'm using the standard FPController and have built a GUI such that I can click on a button and jump my character to a new position within my world. What I'm struggling with is I then need the camera to point at a specific object the instant my character 'lands' in the new position. I don't want the camera to then continue pointing at the object - simply to continue navigating around the world as before.
My script currently is this:
var originalWidth = 1024.0; // define here the original resolution
var originalHeight = 768.0; // you used to create the GUI contents
var BUTTEXT : Texture;
private var scale: Vector3;
var GUI1 : GameObject;
var PLAYER : GameObject;
var TAR : Transform;
function OnGUI(){
scale.x = Screen.width/originalWidth; // calculate hor scale
scale.y = Screen.height/originalHeight; // calculate vert scale
scale.z = 1;
var svMat = GUI.matrix; // save current matrix
// substitute matrix - only scale is altered from standard
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);
// draw your GUI controls here:
GUI.depth = 0;
if (GUI.Button(Rect(656.5,204.5,256,213),BUTTEXT,"")){
Do();
//...
// restore matrix before returning
GUI.matrix = svMat; // restore matrix
}
}
function Do()
{
audio.Play();
yield WaitForSeconds (0.5);
GUI1.SetActiveRecursively(false);
PLAYER.transform.position = TAR.transform.position;
}
Got a bit of scaleable GUI action going on in there but essentially when I click the GUI, the function Do() kills the GUI and moves the FPC to the new position. I'm thinking the Transform.LookAt function is the way to go but i'm not sure where/how to configure it.
Any direction/assistance would be great.
Thanks, James.
Your answer
![](https://koobas.hobune.stream/wayback/20220613113622im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Look at is zooming out 0 Answers
Player looking script 0 Answers
NavMesh agent won't rotate around Y axis 0 Answers
Make player look at pointed target 1 Answer
UI image to point to 3D object 1 Answer