- Home /
transform.lookat() limitation...
void Update () {
transform.position = GetCenterPoint ();
transform.LookAt (targets [1]);
transform.rotation = Quaternion.Euler (0, transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z);
}
Vector3 GetCenterPoint(){
var bounds = new Bounds (targets [0].position, Vector3.zero);
for(int i = 0; i < targets.Count; i++){
bounds.Encapsulate(targets[i].position);
}
return bounds.center;
}
trying to keep the camera from flipping after the character jumps over the lookat transform. Any ideas?
video example: https://photos.app.goo.gl/t37NTQ26oQANf5pm7
what's this script attached to? it feels as if it's attached to the player and the camera is attached to him.
I have a number of objects in the scene and I'm mixing and matching this script on them.
The main idea is that this is on an object that gets forced into the center between the two characters. However, when a character hops over this object, its transform does what the code says, and of course follows it, thereby flipping the screen 180 degrees. It's very jumpy (no pun intended) and unlike any other fighter camera system. This project would be wildly simpler, if there were no 3D side stepping, but I really want it incorporated.
that does not really answer the question what the camera is attached to. If it IS attached to the player, then that's the reason for this behaviour as the camera shouldn't be attached to anything at all, but just sidestep and look.
Answer by tiredamage42 · Jul 07, 2018 at 06:11 PM
You're setting the rotation twice. Store the "look rotation in a local variable, modify that one and then set the rotation. Use Quaternion.LookRotation(target - transform.position) to get the look rotation
Your answer
Follow this Question
Related Questions
Having a plane at exactly the far clip of a camera 1 Answer
My character suddenly stopped looking up/down 0 Answers
Camera transform not responding after load 0 Answers
Parent an objects position without its rotation 1 Answer
LookAt Problem 1 Answer