Unity3D を使用しています。マウス ポインターの方向を向くようにオブジェクトを回転させたいのですが、「毎秒最大 100 度」のような最大回転速度を許可します。
ドキュメントに例がありますが、それは私が望むことをしません。
Time.time は Time.deltaTime であるべきだと思いますが、最後のパラメーターが何をするのかよくわかりません。開始ベクトルに合計される数値になるはずですか?
http://docs.unity3d.com/Documentation/ScriptReference/Quaternion.Slerp.html
また、最後のパラメーターが何をするのか本当に理解できません。ローテーションの時期でしょうか。
今使っているコード
Plane plane = new Plane(Vector3.up, 0);
float dist;
void Update () {
//cast ray from camera to plane (plane is at ground level, but infinite in space)
Ray ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
if (plane.Raycast(ray, out dist)) {
Vector3 point = ray.GetPoint(dist);
//find the vector pointing from our position to the target
Vector3 direction = (point - transform.position).normalized;
//create the rotation we need to be in to look at the target
Quaternion lookRotation = Quaternion.LookRotation(direction);
//rotate towards a direction, but not immediately (rotate a little every frame)
transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * rotationSpeed);
}
}
弱点はSlerpの3番目のパラメータだと思うのですが、そこに何を入れればいいのかわかりません。