我創建了一個使用away3d和離開物體的3D遊戲。Lerping 3D旋轉(away3d)
我創建了一個旋轉公式,它將使我的模型以「平滑因子」旋轉。
private var chRotation:Number = 0;
public override function update(delta:uint):void
{
if(target){
var smooth:Number = 0.95;
var tp:Vector3D = target.ghostObject.position;
var cp:Vector3D = entity.ghostObject.position;
var targetAngle:Number = -((180/Math.PI) * Math.atan2(cp.z - tp.z, cp.x - tp.x));
if(oldTgRotation - targetAngle != 0){
if((oldTgRotation - targetAngle) > 300){
chRotation = -180;
}else if((oldTgRotation - targetAngle) < -300){
chRotation = 180;
}
}
chRotation += (targetAngle + (chRotation - targetAngle) * (smooth - (delta/800))) - chRotation;
entity.ghostObject.rotation = new Vector3D(0, chRotation, 0);
oldTgRotation = targetAngle;
}
}
這個工程部分,它的工作原理,直到目-180旋轉到180 CUS的代碼,然後向後旋轉網格,所以:-180 -90 0 90 180
應該從去 - 前進180到180。但是如何?
編輯:我添加了一種解決方案,但是這仍然是不完美:
if(oldTgRotation - targetAngle != 0){
if((oldTgRotation - targetAngle) > 300){
chRotation = -180;
}else if((oldTgRotation - targetAngle) < -300){
chRotation = 180;
}
}
你也應該看看球面線性插值處理:球面線性插值()](HTTP://的Away3D .com/livedocs/away3d/4.0/away3d/core/math/Quaternion.html#slerp()) –
謝謝,永遠不會注意到其中之一。我會看看以後:) – Duckdoom5