我正在进行一个太空侧滚动游戏的项目,我试图让引擎的相机像一个旧的太空射击游戏一样(单独移动,当玩家的棋子闲置时,将其单独移动到边缘),我试图找到宇宙飞船控制器的教程,但我只找到了陆地单元的相机选项。
我的解决方案是覆盖默认的虚幻相机并自己编程。以下是如何实现这一目标的快速指南。这真的很容易。
第一步是创建自定义的Camera类。此处:
class MyCustomCamera extends Camera;
//Camera variables
var Vector mCameraPosition;
var Rotator mCameraOrientation;
var float mCustomFOV;
/**Init function of the camera
*/
function InitializeFor(PlayerController PC)
{
Super.InitializeFor(PC);
mCameraPosition = Vect(0,0,0);
//Etc...
}
/**Update function of the camera
*/
function UpdateViewTarget(out TViewTarget OutVT, float DeltaTime)
{
//This is the meat of the code, here you can set the camera position at each
//frame, it's orientation and FOV if need be (or anything else really)
OutVT.POV.Location = mCameraPosition;
OutVT.POV.Rotation = mCameraOrientation;
OutVT.POV.FOV = mCustomFOV;
}
下一步也是最后一步是将新的自定义相机设置为默认相机。为此,在您的PlayerController类中添加以下属性块:
CameraClass=class'MyCustomCamera'
现在,对于你对"滚动"相机的特定需求,你可以在更新功能中做一些简单的事情:
/**Update function of the camera
*/
function UpdateViewTarget(out TViewTarget OutVT, float DeltaTime)
{
//This is the meat of the code, here you can set the camera position at each
//frame, it's orientation and FOV if need be (or anything else really)
//This will make your camera move on the X axis at speed 50 units per second.
mCameraPosition += Vect(50*DeltaTime,0,0);
OutVT.POV.Location = mCameraPosition;
OutVT.POV.Rotation = mCameraOrientation;
OutVT.POV.FOV = mCustomFOV;
}
希望这能让你开始!