[Unity]常用技巧收集
Unity 鏡頭拉近效果(帶緩衝)
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);
}
}
Untiy 動畫加速
for (var state : AnimationState in animation)
{
state.speed = 0.5;
}
更多unity2018的功能介紹請到paws3d學習中心查詢。
相關文章
- unity 常用APIUnityAPI
- Unity常用宏Unity
- 常用技巧
- Linux常用資訊收集命令Linux
- kali常用的資訊收集
- 常用的Unity輸入方法Unity
- 收集Chrome控制檯使用技巧點Chrome
- CSS 常用技巧CSS
- 【Idea】常用技巧Idea
- [Idea] 常用技巧Idea
- JS 常用技巧JS
- redis常用demo收集(一)——總起Redis
- linux常用基礎命令操作收集Linux
- faker 資料填充常用指令收集
- win10個人收集小技巧Win10
- 【Unity3D】常用快捷鍵Unity3D
- 【CSS】CSS常用技巧CSS
- css常用技巧梳理CSS
- 50個工作中最常用excel技巧 excel常用技巧大全Excel
- JS常用簡寫技巧JS
- 常用的CSS小技巧CSS
- iView常用元件清空技巧View元件
- LinuxShell常用技巧(目錄)Linux
- JS 常用簡寫技巧JS
- 常用JavaScript的高階技巧JavaScript
- 程式常用的設計技巧
- 30個Python常用小技巧Python
- 【個人總結】常用技巧
- 工具 | 常用 MySQL 核心 Debug 技巧MySql
- 11個常用JS小小技巧JS
- Unity&Shader常用函式的使用方法Unity函式
- 常用應用伺服器——Tomcat的常用小技巧伺服器Tomcat
- Typescript型別常用使用技巧1TypeScript型別
- photoshop常用圖片處理技巧
- 平時收集的一些前端開發技巧總結前端
- 常用前端佈局,CSS技巧介紹前端CSS
- JavaScript常用的簡潔高階技巧JavaScript
- 記錄一些js常用技巧JS