【发布时间】:2019-07-04 05:41:41
【问题描述】:
我有一个播放器对象,以及一个作为子对象连接到它的播放器和相机。
我想将相机绕玩家旋转一圈,使其始终面向玩家(以 0,0,0 为中心)。
我有一个需要转换 3D 的 2D 方法。
这个脚本在 3D 中会是什么样子?
谢谢。
using UnityEngine;
using System.Collections;
public class circularMotion : MonoBehaviour {
public float RotateSpeed;
public float Radius;
public Vector2 centre;
public float angle;
private void Start()
{
centre = transform.localPosition;
}
private void Update()
{
angle += RotateSpeed * Time.deltaTime;
var offset = new Vector2(Mathf.Sin(angle), Mathf.Cos(angle)) * Radius;
transform.localPosition = centre + offset;
}
}
【问题讨论】:
-
你不妨看看四元数 - en.wikipedia.org/wiki/Quaternion
-
如果您不介意使用内置方法,可以使用
Transform.LookAt和Transform.RotateAround来创建想要的效果。 -
@DogeAmazed 我想使用角度方法。