hey , heres my camera script in C# …
using UnityEngine;
using System.Collections;
public class CarCamera : MonoBehaviour
{
public Transform target = null;
public float height = 1f;
public float positionDamping = 3f;
public float velocityDamping = 3f;
public float distance = 50f;
private Vector3 prevVelocity = Vector3.zero;
private Vector3 currentVelocity = Vector3.zero;
void FixedUpdate()
{
currentVelocity = Vector3.Lerp(prevVelocity, target.root.rigidbody.velocity, velocityDamping * Time.deltaTime);
currentVelocity.y = 0;
prevVelocity = currentVelocity;
}
void LateUpdate()
{
float speedFactor = Mathf.Clamp01(target.root.rigidbody.velocity.magnitude / 170.0f);
camera.fieldOfView = Mathf.Lerp(55, 72, speedFactor);
float currentDistance = Mathf.Lerp(45.5f, 6.5f, speedFactor);
currentVelocity = currentVelocity.normalized;
Vector3 newTargetPosition = target.position + Vector3.up * height;
Vector3 newPosition = newTargetPosition - (currentVelocity * currentDistance);
newPosition.y = newTargetPosition.y;
Vector3 targetDirection = newPosition - newTargetPosition;
transform.position = newPosition;
transform.LookAt(newTargetPosition);
}
}
//// And im trying to insert this Raycasting script inside it but its in UnityJavascript and for the life of me I cannot seem to combine the two without errors
function Update () {
var up = transform.TransformDirection(Vector3.up);
var hit : RaycastHit;
Debug.DrawRay(transform.position, -up * 10, Color.green);
if(Physics.Raycast(transform.position, -up, hit, 10)){
Debug.Log("Hit");
if(hit.collider.gameObject.name == "floor"){
Destroy(GetComponent(Rigidbody));
}
}
}
I just want the camera to rise up to stop it going through the terrain ,as two seperatye scripts attached to main camera it works ( I get the raycast warning) but cannot raise the camera up ,(I presume one script is overpowering the other ?) Can anyone help with this please I am totally stuck here ,I seem to have tried everything but failed