Ok, I have been working on a camera script that works as a third person shooter camera system. I know it is flawed and that I should probably rework both sections, However I do not know how exactly.
This is what I want to take from your help (learn/figure out)
-Better Clamping-How can I clamp my camera better on the vertical rotation section. Mainly by assining it rather than moving to that clamp position, because currently I can quickly jerk the mouse and still flip over the clamp limit and get jitters when moving mouse against the clamp instead of a complete stop.
-Better Camera Collision- My current collision has many bugs when you get to close to the camera along a wall that normally cause it to stick to the reference object, and stay on it. I was wondering if their was a more efficient way to do a camera collision while including the following features within it?
+Maximum Camera Distance
+Minimum Distance (so it cant be to close to the player)
+Smooth Transitioning(between positions like returning to the original spot)
and avoid these issues
+See through walls at a angle
+Seeing through the floor
I greatly appreciate any help you can provide, but if you could please try to fully cover one of the sections rather than just parts of it, it would really help. Instead of leaving me mixed up.
Current Script
var ReferenceObject : GameObject;
var posClamp = 60;
var negClamp = -35;
var smoothTime = 0.45;
var dis : float = 4;
private var velocity = Vector3.zero;
//Rotate Empty Vertically
function Update(){
var x = ReferenceObject.transform.localEulerAngles.x;
var y = Input.GetAxis ("Mouse Y");
if(x > 180) x -= 360;
x = Mathf.Clamp(x, negClamp , posClamp);
ReferenceObject.transform.localEulerAngles.x = x;
ReferenceObject.transform.Rotate (-y, 0, 0);
print(x);
}
//Detect Collision with the wall
function LateUpdate () {
var ray : Ray = Ray( ReferenceObject.transform.position, transform.position - ReferenceObject.transform.position);
var hit : RaycastHit;
if(Physics.Raycast(ray, hit, dis)){
transform.position = ray.GetPoint(hit.distance - 1);
}else{
var targetPosition = Vector3(0, 0, -3);
transform.localPosition = Vector3.SmoothDamp(transform.localPosition, targetPosition, velocity, smoothTime);
}
}