0
カメラをドラッグするときにイージングやイナーシャを作って、カメラを落としたときにカメラが落ち着くようにしています。私はそれを投げる/ドラッグする力に基づいてカメラを動かしたいと思います。ユニティカメラスムーズ/イージングドラッグ
これはカメラをドラッグするために使用する実際のコードですが、滑らかなイージングはありません。
using UnityEngine;
using System.Collections;
public class swipeCamera: MonoBehaviour
{
Vector3 hit_position = Vector3.zero;
Vector3 current_position = Vector3.zero;
Vector3 camera_position = Vector3.zero;
float z = 0.0f;
// Use this for initialization
void Start()
{
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
hit_position = Input.mousePosition;
camera_position = transform.position;
}
if (Input.GetMouseButton(0))
{
current_position = Input.mousePosition;
LeftMouseDrag();
}
}
void LeftMouseDrag()
{
// From the Unity3D docs: "The z position is in world units from the camera." In my case I'm using the y-axis as height
// with my camera facing back down the y-axis. You can ignore this when the camera is orthograhic.
current_position.z = hit_position.z = camera_position.y;
// Get direction of movement. (Note: Don't normalize, the magnitude of change is going to be Vector3.Distance(current_position-hit_position)
// anyways.
Vector3 direction = Camera.main.ScreenToWorldPoint(current_position) - Camera.main.ScreenToWorldPoint(hit_position);
// Invert direction to that terrain appears to move with the mouse.
direction = direction * -1;
Vector3 position = camera_position + direction;
transform.position = position;
}
}
ありがとう!
zwcloud非常に魅力的なように働いてくれてありがとう!本当にあなたの助けに感謝します!あなたは新しい仲間を獲得しました。 – PizzaMonster
私はそれが助けてうれしいです。あなたができる時upvoteに覚えておいてください。 :) – zwcloud
ちょっと人、後半の提案だけど、誰かがこれをもう一度読んでくれたらね:) 私は 'Vector3.Lerp()'を使用します。これは、最後にゆっくりと減少するため、よりスムーズなカメラの動きを与えます。 'transform.position = Vector3.Lerp(transform.position、targetPos、Time.deltaTime * DragSpeed);' –