我正在用自动照相机创建游戏。我希望这台摄像机显示播放器正在向何处移动。该游戏使玩家可以进行多种动作,而不仅仅是3D走动。因此,例如,如果玩家跌倒在地面上,则相机应将自身定位在玩家上方,并向下看地面和地面。而且,如果播放器向前移动,则相机应将自身定位在播放器后面,向前看。
我在下面尝试的所有内容中都包含了我认为是最好的实现,并附有解释功能和一些问题的评论。
l = [name for name in name_list2 if name in hash1]
答案 0 :(得分:0)
好的,所以我想我已经把这个包裹了。相机和播放器之间似乎存在剪切/相交的问题,导致相机的行为异常。我设置了一个小项目,导入了第三人称Standard Unity Controller,并将您的代码复制到了相机。起初,我遇到了相机从侧面显示播放器的问题。因此,然后我在摄像机的起始位置添加了一个静态矢量,以纠正摄像机与“第三人称角色”重叠的问题,并解决了该问题(至少对我和我的设置而言)。这是“相机”组件的“更新”功能。
///This should position the camera in a straight line between the player and the direction the player is heading. This seems to work to work nearly as expected, but seems to line up to what I believe to be the opposite direction in some cases.
v3T = player.transform.position + new Vector3(5,5,5); //- (player.GetComponent<Rigidbody>().velocity - player.transform.position);
p2 = player.transform.position + v3T.normalized * 7.0f;
finalP = Vector3.SmoothDamp(finalP,p2,ref velocity, 0.002f, 850f);
transform.position = new Vector3(finalP.x, finalP.y, finalP.z);
//Using a LookAt like this leads for decent results, but not perfect. Possibly due to me not lining up the camera correctly?
transform.LookAt(player.transform.position);
//Using a Lookat in direction the player is moving doesn't give me the expected result. It seems to lose track of the player easily, and doesn't go in the direction that I thought it would at all times.
//transform.LookAt(player.GetComponent<Rigidbody>().velocity)
以下是我screenshots进行的一些设置和相机的行为。