(对于 Unity 5.3.5f1)现在我正在制作一个 3D 摄像机,它围绕玩家水平旋转。玩家是一个刚体滚动球体。玩家可以自由水平旋转轴,但是当没有输入时,我希望旋转重置回速度方向。
现在我只需要知道如何通过从之前的旋转围绕玩家旋转相机来将相机定位在玩家速度方向的后面。
目前要更新相机以围绕播放器运行,我在相机上使用此脚本(带注释):
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public GameObject Player;
//I assume you would use this PlayerRB to find data regarding the movement or velocity of the player.
//public Rigidbody PlayerRB;
private float moveHorizontalCamera;
private Vector3 offset;
// Use this for initialization
void Start ()
{ //the offset of the camera to the player
offset = new Vector3(Player.transform.position.x - transform.position.x, transform.position.y - Player.transform.position.y, transform.position.z - Player.transform.position.z);
}
// Update is called once per frame
void Update ()
{
moveHorizontalCamera = Input.GetAxis("Joy X"); //"Joy X" is my right joystick moving left, none, or right resulting in -1, 0, or 1 respectively
//Copied this part from the web, so I half understand what it does.
offset = Quaternion.AngleAxis(moveHorizontalCamera, Vector3.up) * offset;
transform.position = Player.transform.position + offset;
transform.LookAt(Player.transform.position);
}
}
任何帮助都会很棒!