我正在开发统一的赛车游戏。我将汽车移动脚本放在机器人汽车和主摄像头中。相机在向前移动时跟随汽车,但当汽车与其他物体相撞时,汽车改变了位置,或者当我转弯时,汽车也转向相机,但早于汽车,因此汽车超出了范围。我试着把角色控制器,试着把相机的层次结构,它不能顺畅地跟随汽车,即使是顺畅的跟随脚本。所以告诉我任何一种方式让相机跟随汽车,就像我们在其他赛车游戏中看到的那样。
发布于 2015-09-24 13:28:53
对于这种类型的游戏(摄像机设置为跟随某个对象,从A地到B地),我建议将一个空游戏对象设置为父对象,其中您希望摄像机结束于汽车,并将另一个空游戏对象设置为汽车的父对象,以确定您希望摄像机观看的位置。
在这之后,使用基本的相机跟随和相机观看脚本,这些脚本与标准资源一起使用,并使用平滑因子来适合您的游戏。您必须确保为您的项目导入了脚本包。
或者,如果包已导入,请选择您的相机,转到组件菜单,然后在“相机控制”下选择“平滑跟随”脚本。
如果你需要摄像头根据(例如)汽车在路上的位置来动态改变位置,我会考虑相同的解决方案,但使用iTween沿着预定义的路径改变两个游戏对象的位置。
更多关于:http://docs.unity3d.com/ScriptReference/Transform.LookAt.html lookat:http://wiki.unity3d.com/index.php/SmoothFollow2 lookat:smoothfollow
发布于 2021-12-19 17:44:43
设置游戏摄像头真的很有挑战性,特别是当涉及到车辆摄像头控制时,因为摄像头的移动速度取决于车辆的速度,并且使用C#脚本控制车辆的摄像头有点困难。
我强烈建议你使用unity build in‘Cinemachine Package’,你可以免费安装它。如果您想了解影院机器,请继续查看此视频https://www.youtube.com/watchv=X33t13gOBFw&list=PLOBPWyvPXShNN01VQ1LLPqfCtqeRo95Z1&index=23,顺便说一句,在此视频中,他们为vehicle
设置了影院机器摄像机
发布于 2021-12-19 21:19:29
你可以的
将相机设置为您的汽车的孩子(您想要跟随的对象),编写此代码taken from here
using UnityEngine;
using System.Collections;
public class CameraController : 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;
}
}https://stackoverflow.com/questions/32753827
复制相似问题