- Home /
Camera Heights
Hi all! I have a third person camera working with my custom controller(it's really the orbit camera script with some clipping and controller device modifications, and it moves smoothly). The thing is, is that when the player jumps, so does the camera. How can I make the camera change its height only when the player is high enough? I think it has something to do with screen bounds or something like that.
Any help would be great! :) Camera:
#pragma strict
#pragma implicit
#pragma downcast
var target : Transform;
var layermask : LayerMask;
var distance = 20.0;
var height = 1.0;
var xSpeed = 180.0;
var ySpeed = 180.0;
var xOffset = 2.0;
var yOffset = 4.0;
var yMinLimit = -15;
var yMaxLimit = 75;
var smoothTime = 0.20;
private var x = 0.0;
private var y = 0.0;
private var xSmooth = 0.0;
private var ySmooth = 0.0;
private var xVelocity = 0.0;
private var yVelocity = 0.0;
private var posSmooth = Vector3.zero;
private var posVelocity = Vector3.zero;
@script AddComponentMenu("Camera-Control/Mouse Orbit")
function Update(){
if(y > yMaxLimit){
y = yMaxLimit;
}
if(y < yMinLimit){
y = yMinLimit;
}
}
function Start () {
var angles = transform.eulerAngles;
x = angles.y;
y = angles.x;
transform.position = target.transform.position;
}
function LateUpdate () {
if (target){
x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
x += Input.GetAxis("Stick X") * xSpeed * 0.02;
y -= Input.GetAxis("Stick Y") * ySpeed * 0.02;
xSmooth = Mathf.SmoothDamp(xSmooth, x, xVelocity, smoothTime);
ySmooth = Mathf.SmoothDamp(ySmooth, y, yVelocity, smoothTime);
ySmooth = ClampAngle(ySmooth, yMinLimit, yMaxLimit);
var rotation = Quaternion.Euler(ySmooth, xSmooth, 0);
posSmooth = Vector3.SmoothDamp(posSmooth,target.position,posVelocity,smoothTime);
transform.rotation = rotation;
transform.position = rotation * Vector3(xOffset, yOffset, -distance) + posSmooth;
}
var hit : RaycastHit;
if(Physics.Linecast(target.position, transform.position,hit,layermask)){
var tempDistance = Vector3.Distance(target.position,hit.point);
position = rotation * Vector3(xOffset, yOffset, -tempDistance) + target.position;
transform.position = position;
}
}
static function ClampAngle (angle : float, min : float, max : float) {
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp (angle, min, max);
}
Sorry if it's a lot of code, let me know if I need to cut out some script! Thank you!
Your answer
Follow this Question
Related Questions
3rd person player 0 Answers
Android deltaPosition.y isn't working? 1 Answer
Getting a scrolling camera to orbit around a circular walkway, following the player? 1 Answer
3rd person camera reset bug 0 Answers
Camera orbit around clicked position 0 Answers