Skip to content

Commit

Permalink
回転時にアニメーションする機能を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
ktaka committed Sep 1, 2019
1 parent 5012f8a commit f22b1f3
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions ARKitten/Assets/Scripts/PlaceObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ public class PlaceObject : MonoBehaviour
public GameObject placedPrefab; // 配置用モデルのプレハブ
public bool useAR = true; // AR使用フラグ(プレイモードで実行する際はfalseにする)
public GameObject floorPlane; // プレイモード用の床面

public float rotateDuration = 3.0f;
public float delayTime = 3.0f;

GameObject spawnedObject; // 配置モデルのプレハブから生成されたオブジェクト
// ARRaycastManagerは画面をタッチした先に伸ばしたレイと平面の衝突を検知する
ARRaycastManager raycastManager;
ARSessionOrigin arSession;
static List<ARRaycastHit> hits = new List<ARRaycastHit>();
Quaternion rotateFrom;
Quaternion rotateTo;
float rotateDelta;

// 起動時に1度呼び出される
void Start()
Expand All @@ -38,7 +43,16 @@ void Update()
{
if (spawnedObject != null)
{
CheckObjDirection();
if (rotateDelta <= 0.0f)
{
ResetRotateAnim();
CheckObjDirection();
}
else
{
RotateCamera();
rotateDelta -= Time.deltaTime;
}
}

// タッチされていない場合は処理をぬける
Expand Down Expand Up @@ -84,7 +98,23 @@ void CheckObjDirection()
float dot = Vector3.Dot(catDirVector, lookVector);
if (dot <= 0.5f)
{
spawnedObject.transform.rotation = Quaternion.LookRotation(lookVector);
rotateFrom = spawnedObject.transform.rotation;
rotateTo = Quaternion.LookRotation(lookVector);
rotateDelta = rotateDuration + delayTime;
}
}

void ResetRotateAnim()
{
rotateDelta = 0.0f;
}

void RotateCamera()
{
if (rotateDelta <= rotateDuration)
{
float t = 1.0f - (rotateDelta / rotateDuration);
spawnedObject.transform.rotation = Quaternion.Slerp(rotateFrom, rotateTo, t);
}
}

Expand Down

0 comments on commit f22b1f3

Please sign in to comment.