【发布时间】:2018-01-20 17:21:58
【问题描述】:
我正在制作一个游戏(2D),其中一个对象以一定速度运行并跳到即将到来的平台上,并且我已将相机作为层次结构中游戏对象(即主要玩家)的子对象。问题是,每当我的游戏对象在撞击平台或障碍物时旋转时,主摄像机也会开始旋转。我无法解决这个问题,有人可以帮忙吗?
【问题讨论】:
标签: unity3d camera unity5 game-engine game-physics
我正在制作一个游戏(2D),其中一个对象以一定速度运行并跳到即将到来的平台上,并且我已将相机作为层次结构中游戏对象(即主要玩家)的子对象。问题是,每当我的游戏对象在撞击平台或障碍物时旋转时,主摄像机也会开始旋转。我无法解决这个问题,有人可以帮忙吗?
【问题讨论】:
标签: unity3d camera unity5 game-engine game-physics
您可以在 Inspector 中锁定相机的旋转,也可以创建一个 Camerascript 来跟随您的玩家 manuell。 Seconded 更好,因为您可以轻松添加平滑、死区或相机效果,例如对拍摄到相机的 dmg 进行抖动。
统一页面中的脚本示例:
using UnityEngine;
using System.Collections;
public class CompleteCameraController : MonoBehaviour
{
public GameObject player; //Public variable to store a reference to the player game object
private Vector3 offset; //Private variable to store the offset distance between the player and camera
// Use this for initialization
void Start ()
{
//Calculate and store the offset value by getting the distance between the player's position and camera's position.
offset = transform.position - player.transform.position;
}
// LateUpdate is called after Update each frame
void LateUpdate ()
{
// Set the position of the camera's transform to be the same as the player's, but offset by the calculated offset distance.
transform.position = player.transform.position + offset;
}
}
将此脚本添加到您的 MainCamera。然后将您的 PlayerObject 拖到相机检查器中的“玩家”字段中。
如果您需要更多帮助,请观看此视频here
【讨论】: