- Home /
Transform.LookAt snaps back to it's last location
I am using the First Person Controller. I am trying to set it up so that when my character goes to sleep they wake up looking at a certain point in the room. My code disables all scripts on the player, looks at the object and then re-enables all the scripts after about 3 seconds. This all works swimmingly.
My problem is that as soon as the scripts on the player are re-enabled the camera immediately returns to its last position before it called LookAt. I'm fairly certain that this is being caused by the FPC telling the camera to look at a certain point dictated by the mouse movement but I'm not entirely sure and I don't know how I'd fix that.
Answer by ScaniX · Jun 22, 2016 at 04:07 PM
Yes, it is the MouseLook. Whenever you rotate the camera, you have to set the values in the MouseLook as well, so it does not rotate immediately back to the old target values.
I am using this method in my MouseLook class (cannot really remember if it was there from the beginning or if I wrote it ^^):
internal void Reset(Quaternion rotation) {
Vector3 rotEuler = rotation.eulerAngles;
Quaternion camRot = Quaternion.Euler(rotEuler.x, 0, 0);
Quaternion playerRot = Quaternion.Euler(0, rotEuler.y, 0);
m_CharacterTargetRot = playerRot;
m_CameraTargetRot = camRot;
}
BTW: My answers still have over a day delay because of moderation if anybody wonders why I am answering closed question. They are not answered at the time I try to... XD
Your answer
Follow this Question
Related Questions
I need help writing a simple script for making an object face the mouse in 2D. 2 Answers
Need to vertically space buttons in scripting C# 1 Answer
Non stopping point - counter 1 Answer
allowing only one child object per paremnt object at any given time. 0 Answers
Why do placing a preprocessor directive inside another causes my script to lose proper indentation? 1 Answer