- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
sooraj · May 29, 2015 at 05:33 AM ·
camerajavascriptcamera-movementscriptingbasicscar
how to modify this code to place it inside a car and move it along the car.
how to modify this code to move it along the direction the car goes.The problem is the camera dont turn correctly when the car turns.Also provide the code to turn camera to 180 degree when the car goes reverse.
#pragma strict
var car : Transform;
var distance : float = 6.4;
var height : float = 1.4;
var rotationDamping : float = 3.0;
var heightDamping : float = 2.0;
var zoomRacio : float = 0.5;
var DefaultFOV : float = 60;
private var rotationVector : Vector3;
function Start () {
}
function LateUpdate () {
var wantedAngel = rotationVector.y;
var wantedHeight = car.position.y + height;
var myAngel = transform.eulerAngles.y;
var myHeight = transform.position.y;
myAngel = Mathf.LerpAngle(myAngel,wantedAngel,rotationDamping*Time.deltaTime);
myHeight = Mathf.Lerp(myHeight,wantedHeight,heightDamping*Time.deltaTime);
var currentRotation = Quaternion.Euler(0,myAngel,0);
transform.position = car.position;
transform.position -= currentRotation*Vector3.forward*distance;
transform.position.y = myHeight;
transform.LookAt(car);
}
function FixedUpdate (){
var localVilocity = car.InverseTransformDirection(car.rigidbody.velocity);
if (localVilocity.z<-0.5){
rotationVector.y = car.eulerAngles.y + 180;
}
else {
rotationVector.y = car.eulerAngles.y;
}
var acc = car.rigidbody.velocity.magnitude;
camera.fieldOfView = DefaultFOV + acc*zoomRacio;
}
Comment
Your answer
Follow this Question
Related Questions
Camera Control messing up.. 1 Answer
Camera Script Amalgamation == Camera Script Abomination, Im In Over My Head 0 Answers
Refining a 3d side scroller camera script 0 Answers
How to make the camera look ahead of the player when he is moving 2 Answers
Z Rotation with Limits does not function properly. 0 Answers