简体   繁体   English

Unity Sub Camera 跟随播放器出现旋转问题

[英]Unity Sub Camera following Player with rotation problem

Here is an image of what I'm trying to achieve这是我想要实现的图像我正在写的游戏的游戏画面

As you can tell it's a split screen game, the player is on the left, computer on the right.可以看出这是一款分屏游戏,玩家在左边,电脑在右边。 there are 3 cameras in the game, main and two player cameras游戏中有 3 个摄像头,主摄像头和两个玩家摄像头

the player camera MUST be independent of the player and CAN NOT be a child object of the player object, because the ball bounces and rotates while moving, the cameras must not.玩家相机必须独立于玩家,不能是玩家 object 的子 object,因为球在移动时会反弹和旋转,所以相机不能。 when the balls change direction the camera must remain behind the player so the visual appears to show the landscape rotating with the player.当球改变方向时,摄像机必须保持在玩家身后,这样视觉效果才会显示出随着玩家旋转的风景。 I've searched high and low for anything to put me on the right path but nothing seems to work right.我到处寻找任何能让我走上正确道路的东西,但似乎没有任何东西能正常工作。 It should be a smooth transition so lerp and slerp are to slow for instant moving.这应该是一个平稳的过渡,所以 lerp 和 slerp 会为了即时移动而放慢速度。 I know LateUpdate will help with this.我知道 LateUpdate 会对此有所帮助。 If anyone can point me in the right direction I'd appreciate it.如果有人能指出我正确的方向,我将不胜感激。

Many thanks, Paul非常感谢,保罗

Have a script which takes in an object's position, in this case the player's ball, so you can code the camera as if it was a child of the object.有一个脚本可以接收对象的 position,在本例中是玩家的球,因此您可以将相机编码为 object 的子对象。

An simple example code for having a following camera would be something like...拥有跟随相机的简单示例代码将类似于...

FollowObject.cs跟随对象.cs

public Transform exampleObject;
private int offset = 5; //How far back the camera will be

void LateUpdate()
{
    transform.position = new Vector3(exampleObject.transform.position.x,
                                     exampleObject.transform.position.y, 
                                     exampleObject.transform.position.z - offset)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM