away3d と awayphysics を使用して 3D ゲームを作成しています。
「スムーズ係数」でモデルを回転させる回転式を作成しました。
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 に回転するまで機能します。コードはメッシュを後方に回転させます。-180 -90 0 90 180
-180 から 180 に進む必要があります。しかし、どのように?
編集:私は一種の解決策を追加しましたが、これはまだ完全ではありません:
if(oldTgRotation - targetAngle != 0){
if((oldTgRotation - targetAngle) > 300){
chRotation = -180;
}else if((oldTgRotation - targetAngle) < -300){
chRotation = 180;
}
}