带缓冲的镜头拉近效果(Unity)
温柔似野鬼°
595次浏览
2020年07月30日 17:09
最佳经验
本文由作者推荐
9寸-男拼音
大家应该见过,一些游戏中,当玩家发现了某样东西,摄像机会马上移动过去,但在快到的时候会减慢速度,这个代码实现的就是那个效果。
复制代码
摄像机的效果代码系列——带缓冲的镜头拉近效果!
大家应该见过,一些游戏中,当玩家发现了某样东西,摄像机会马上移动过去,但在快到的时候会减慢速度,这个代码实现的就是那个效果。
复制代码
var target : Transform;
var distance : float = 3.0;
var height : float = 1.0;
var damping : float = 5.0;
var smoothRotation : boolean = true;
var rotationDamping : float = 10.0;
// allows offsetting of camera lookAt, very useful for low bumper heights
var targetLookAtOffset : Vector3;
// length of bumper ray
var bumperDistanceCheck : float = 2.5;
// adjust camera height while bumping
var bumperCameraHeight : float = 1.0;
// allows offset of the bumper ray from target origin
var bumperRayOffset : Vector3;
function FixedUpdate() {
var wantedPosition = ormPoint(0, height, -distance);
// check to see if there is anything behind the target
var hit : RaycastHit;
var back = ormDirection(-1 * d);
// cast the bumper ray out from rear and check to see if there is anything behind
if (t(ormPoint(bumperRayOffset), back, hit, bumperDistanceCheck)) {
// clamp wanted position to hit position
wantedPosition.x = .x;
wantedPosition.z = .z;
wantedPosition.y = (.y + bumperCameraHeight, wantedPosition.y, ime * damping);
}
on = (on, wantedPosition, ime * damping);
var lookPosition : Vector3 = ormPoint(targetLookAtOffset);
if (smoothRotation) {
var wantedRotation : Quaternion = tation(lookPosition - on, );
on = (on, wantedRotation, ime * rotationDamping);
} else {
on = tation(lookPosition - on, );
}
}