C# Unity3d自顶向下相机控制
我在Unity3D中有一个自上而下的游戏,玩家可以控制一辆车。现在,照相机将汽车保持在屏幕中间,并旋转到汽车指向的方向。< /P> 我就是这样做的:C# Unity3d自顶向下相机控制,c#,unity3d,rotation,C#,Unity3d,Rotation,我在Unity3D中有一个自上而下的游戏,玩家可以控制一辆车。现在,照相机将汽车保持在屏幕中间,并旋转到汽车指向的方向。< /P> 我就是这样做的: public class CameraFollowController : MonoBehaviour { private void FixedUpdate() { transform.rotation = Quaternion.Euler(90, car.rotation.eulerAngles.y + 90, 9
public class CameraFollowController : MonoBehaviour
{
private void FixedUpdate()
{
transform.rotation = Quaternion.Euler(90, car.rotation.eulerAngles.y + 90, 90);
transform.position = new Vector3(car.position.x, cameraHeight, car.position.z);
}
public Transform car;
public float cameraHeight = 10;
}
我想改变摄像头的位置,使汽车始终位于屏幕底部:
如何做到这一点?看起来您正在尝试偏移相机在Z轴上的位置 您需要做的是找出车辆在屏幕底部的位置偏移量,并将其应用为
FixedUpdate()
循环中的Z轴偏移量
transform.position=新矢量3(car.position.x、cameraHeight、car.position.z*-/+*zCamOffset)代码>
一个相当简单和粗略的方法是,在游戏模式下,移动汽车游戏对象,使其位于游戏窗口底部的位置。然后使用汽车游戏对象变换组件Z轴上的值作为粗略偏移
祝你好运 看起来您正在尝试偏移相机在Z轴上的位置
您需要做的是找出车辆在屏幕底部的位置偏移量,并将其应用为FixedUpdate()
循环中的Z轴偏移量
transform.position=新矢量3(car.position.x、cameraHeight、car.position.z*-/+*zCamOffset)代码>
一个相当简单和粗略的方法是,在游戏模式下,移动汽车游戏对象,使其位于游戏窗口底部的位置。然后使用汽车游戏对象变换组件Z轴上的值作为粗略偏移
祝你好运 如果车辆在x/y轴上移动,您可以使用transform.forward
获取车辆所面对的方向,然后进行调整
public float distance; // How much you want to offset
// Get the direction of the car
Vector3 dir = car.transform.forward;
// Offset the position
transform.position += -dir * distance;
如果车辆在x/y轴上移动,可以使用transform.forward
获取车辆所面对的方向,然后进行调整
public float distance; // How much you want to offset
// Get the direction of the car
Vector3 dir = car.transform.forward;
// Offset the position
transform.position += -dir * distance;
请尝试在发布之前解决您的问题请尝试在发布之前解决您的问题谢谢先生,我感谢您的建议,我已经尝试过了,但它不能满足我的需要。这种解决方案不会让汽车一直处于屏幕底部。谢谢你,先生,我很感谢你的建议,我已经尝试过了,但它不能满足我的需要。这种解决方案不会让汽车一直处于屏幕底部。非常感谢,@Savaria!这正是我需要的!非常感谢,@Savaria!这正是我需要的!