I am using this script, to detect collision from camera. (attached to player, ray pointed at camera)
var player : GameObject;
function Update () {
var ray : Ray = Ray(player, player.transform.position - transform.position);
var hit : RaycastHit;
if(Physics.Raycast(ray, hit)){
Camera.main.transform.position = ray.GetPoint(hit.distance-1);
}
}
I keep getting this error.
Error
Assets/Scripts/Camera/CameraCollision.js(7,28): BCE0024: The type 'UnityEngine.Ray' does not have a visible constructor that matches the argument list '(UnityEngine.GameObject, UnityEngine.Vector3)'.
Error At
var ray : Ray = Ray(player, player.transform.position - transform.position);
I have it working but It will detect Extremely far away and it is jittery.
How would I use RaycastHit.distance to make it only cast only so far ?
and how would I make them smooth transitions instead of jittery ?
If could do like small example scripts please would be helpful so i know how to use them.
Here is the code currently.
var Camera : GameObject;
function Update () {
var ray : Ray = Ray(transform.position, Camera.transform.position - transform.position);
var hit : RaycastHit;
if(Physics.Raycast(ray, hit)){
Camera.transform.position = ray.GetPoint(hit.distance-1);
}else{
Camera.transform.localPosition = Vector3(0.0, 3.3, -5.4);
}
}