- Home /
Return camera to original rotation values Logic
The title might not be very descriptive. I now how to to this, I just can't think of a logical way to implement it, if that makes any sense...Please read I have a camera parented to a truck(the player). If the player starts doing flips and stuff, upon landing the camera will be rotated in some weird manner. I have a script that was written mostly by my instructor, for the camera to make the view lag a bit when you turn the truck, as if the camera were a balloon attached to the truck by a string. By disabling that script and testing the game, I determined that the issue is a result of the script, but I would like very much to keep it. My idea was this
var camRotX : float;
var camRotZ : float;
function Start(){ //defines original rotation values
camRotX = transform.rotation.eulerAngles.x;
camRotZ = transform.rotation.eulerAngles.z;
}
function Update (){ //sets current rotation values to original
transform.rotation.eulerAngles.x = camRotX;
transform.rotation.eulerAngles.z = camRotZ;
}
This worked, except that it was maintaining the rotation of the camera constantly, so if you were to go up a slope, the camera would stare at the side of the mountain while the truck rotated with the grade. I thought maybe setting the rotation values only when the truck collides with the terrain would work, but I have no idea how to make my camera know when the truck hits the ground. I was thinking maybe some sort of ParentOnCollisionEnter might exist but I couldn't find anything in the scripting API.
I don't think it's necessary, but just in case, here is the whole script.
var frameCounter : int = 0;
var frameCycle_01 : int;
var frameCycle_02 : int = 0;
var rot_Y : float[] = new float[10];
var camRotX : float;
var camRotZ : float;
function Start(){
camRotX = transform.rotation.eulerAngles.x;
camRotZ = transform.rotation.eulerAngles.z;
}
function Update () {
frameCycle_01 = frameCounter%10;
frameCycle_02 = (frameCounter + 1)%10;
rot_Y[frameCycle_01] = TruckDriver.truckRotation.y;
transform.rotation.eulerAngles.y = rot_Y[frameCycle_02];
transform.rotation.eulerAngles.x = camRotX;
transform.rotation.eulerAngles.z = camRotZ;
frameCounter++;
}
Answer by CScherer549 · Jul 20, 2014 at 08:06 PM
You're close with that first script, just think about what conditions you want those initial rotations to be applied. Probably not all the time right? If you're using a character controller, look into controller.isGrounded.
Your answer
Follow this Question
Related Questions
Make camera 1 transform equal to camera 2 transform 1 Answer
Why is my Camera rotation tilted after parenting it to head? 1 Answer
NullReferenceException Error 1 Answer
LookAround Up&Down! 1 Answer
How to rotate my camera? 2 Answers