Hiall!
I'm new in scripting and i'm approacing step by step, tutorial by tutorial and headache by headache :)...ok let me explain my problem.
I'm doing a simple test, with a character moving on a plane, and the camera that follow the character only on sliding (mmm...like zelda!), then I added a little smooth to the camera with the mathf.lerp, here is my code:
//smoothfollow camera script
var target : Transform;
var distance = 3.0;
var slide = 2.0;
var heightDamping = 10;
var rotationDamping = 3.0;
function Update () {
// Early out if we don't have a target
if (!target)
return;
// Calculate the current rotation angles
//wantedRotationAngle = target.eulerAngles.y;
wantedSlidex = target.position.x;
wantedSlidez = target.position.z - 5;
//currentRotationAngle = transform.eulerAngles.y;
currentSlidex = transform.position.x;
currentSlidez = transform.position.z;
// Damp the rotation around the y-axis
//currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
// Damp the height
currentSlidex = Mathf.Lerp (currentSlidex, wantedSlidex, heightDamping * Time.deltaTime);
currentSlidez = Mathf.Lerp (currentSlidez, wantedSlidez, heightDamping * Time.deltaTime);
// Convert the angle into a rotation
//currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
// Set the position of the camera on the x-z plane to:
// distance meters behind the target
transform.position.z = currentSlidez;
transform.position.y = target.position.y +2;
//transform.position -= target.position * distance;
// Set the height of the camera
transform.position.x = currentSlidex;
// Always look at the target
transform.LookAt (target);
}
and here my moving script:
var speed = 10;
var gravity = 20.0;
private var moveDirection = Vector3.zero;
function FixedUpdate() {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
Input.GetAxis("Vertical"));
if (moveDirection != Vector3.zero) {
var rotation = transform.rotation;
rotation.SetLookRotation(moveDirection);
transform.rotation = rotation;
}
moveDirection *= speed;
}
if (Input.GetButton ("Jump")) {
moveDirection.y = 3;
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}
@script RequireComponent(CharacterController)
The problem is that the character is perfect in movement but the background shakes a bit with a terrible jitter...you can see th problem directly downloading the .exe project.
Any suggestion or semplification to my code will be accepted :D...
Project exe download: http://rapidshare.com/files/435362527/lolworlds.exe
Thank's a lot!