如何制作UDK相机(虚幻开发工具包)沿着侧面滚动移动?

时间:2013-07-10 22:18:31

标签: unreal-development-kit

我正在进行一个空间侧滚动游戏的项目,我试图使引擎的相机像旧的太空射击游戏一样(单独移动,当玩家棋子保持闲置时,将其单独移动到其边缘),我试图找到太空船控制器的教程,但我只找到了陆地单位的摄像头选项。

1 个答案:

答案 0 :(得分:0)

我的解决方法是覆盖默认的虚幻相机并自行编程。以下是如何完成此操作的快速指南。这真的很容易。

第一步是创建自定义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类中添加这是defaultproperties块:

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;
}

希望这能让你开始!