? 97精品无码视频在线,久久亚洲精中文字幕,中国成人免费视频
聯(lián)系我們

給我們留言

聯(lián)系我們

地址:福建省晉江市青陽街道洪山路國際工業(yè)設(shè)計(jì)園納金網(wǎng)

郵箱:info@narkii.com

電話:0595-82682267

(周一到周五, 周六周日休息)

當(dāng)前位置:主頁 > 3D教程 > 3D技巧分享

unity攝像機(jī)的效果代碼

來源: | 責(zé)任編輯:她。 | 發(fā)布時(shí)間: 2013-07-03 09:08 | 瀏覽量:

   攝像機(jī)的效果代碼系列——帶緩沖的鏡頭拉近效果!
大家應(yīng)該見過,一些游戲中,當(dāng)玩家發(fā)現(xiàn)了某樣?xùn)|西,攝像機(jī)會(huì)馬上移動(dòng)過去,但在快到的時(shí)候會(huì)減慢速度,這個(gè)代碼實(shí)現(xiàn)的就是那個(gè)效果。


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;

var targetLookAtOffset : Vector3; // allows offsetting of camera lookAt, very useful for low bumper heights

var bumperDistanceCheck : float = 2.5; // length of bumper ray
var bumperCameraHeight : float = 1.0; // adjust camera height while bumping
var bumperRayOffset : Vector3; // allows offset of the bumper ray from target origin

function FixedUpdate() {

var wantedPosition = target.TransformPoint(0, height, -distance);

// check to see if there is anything behind the target
var hit : RaycastHit;
var back = target.transform.TransformDirection(-1 * Vector3.forward);

// cast the bumper ray out from rear and check to see if there is anything behind
if (Physics.Raycast(target.TransformPoint(bumperRayOffset), back, hit, bumperDistanceCheck)) {
// clamp wanted position to hit position
wantedPosition.x = hit.point.x;
wantedPosition.z = hit.point.z;
wantedPosition.y = Mathf.Lerp(hit.point.y + bumperCameraHeight, wantedPosition.y, Time.deltaTime * damping);
}

transform.position = Vector3.Lerp(transform.position, wantedPosition, Time.deltaTime * damping);

var lookPosition : Vector3 = target.TransformPoint(targetLookAtOffset);

if (smoothRotation) {
var wantedRotation : Quaternion = Quaternion.LookRotation(lookPosition - transform.position, target.up);
transform.rotation = Quaternion.Slerp(transform.rotation, wantedRotation, Time.deltaTime * rotationDamping);
} else {
transform.rotation = Quaternion.LookRotation(lookPosition - transform.position, target.up);
}
}

相關(guān)文章
網(wǎng)友評(píng)論

您需要登錄后才可以發(fā)帖 登錄 | 立即注冊(cè)

關(guān)閉

全部評(píng)論:0條

推薦
熱門