Элементарный 2d вид в UDK

В этой статье я расскажу как сделать самый простой вид камера постоянно с боку и наш персонаж бегает только по одной оси координат.




Для начало надо создать новую папку допустим "NewGames" в  \UDK-20хх-хх\Development\Src\  и в ней папку "Classes" и  положить туда три файла :

NewGamesInfo.uc

class NewGamesInfo extends UTDeathmatch;

defaultproperties
{
    Acronym="MG"    
    PlayerControllerClass=class'UDNPlayerController'
    DefaultPawnClass=class'UDNPawn'
    Name="Default__NewGamesInfo"
}

UDNPawn.uc


class UDNPawn extends UTPawn;

var float CamOffsetDistance;

simulated event BecomeViewTarget( PlayerController PC )
{
   local UTPlayerController UTPC;

   Super.BecomeViewTarget(PC);

   if (LocalPlayer(PC.Player) != None)
   {
      UTPC = UTPlayerController(PC);
      if (UTPC != None)
      {
         UTPC.SetBehindView(true);
         SetMeshVisibility(UTPC.bBehindView);
         UTPC.bNoCrosshair = true;
      }
   }
}

simulated function bool CalcCamera( float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV )
{
   out_CamLoc = Location;
   out_CamLoc.Y = CamOffsetDistance;

   out_CamRot.Pitch = 0;
   out_CamRot.Yaw = 16384;
   out_CamRot.Roll = 0;
   return true;
}

simulated singular event Rotator GetBaseAimRotation()
{
   local rotator   POVRot;

   POVRot = Rotation;
   if( (Rotation.Yaw % 65535 > 16384 && Rotation.Yaw % 65535 < 49560) ||
      (Rotation.Yaw % 65535 < -16384 && Rotation.Yaw % 65535 > -49560) )
   {
   POVRot.Yaw = 32768;
   }
   else
   {
      POVRot.Yaw = 0;
   }
   
   if( POVRot.Pitch == 0 )
   {
      POVRot.Pitch = RemoteViewPitch << 8;
   }

   return POVRot;
}   

defaultproperties
{
   CamOffsetDistance=0.0
}


UDNPlayerController.uc

class UDNPlayerController extends UTPlayerController;
state PlayerWalking
{
ignores SeePlayer, HearNoise, Bump;
function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
   {
      local Rotator tempRot;

      if( Pawn == None )
      {
         return;
      }

      if (Role == ROLE_Authority)
      {
         // Update ViewPitch for remote clients
         Pawn.SetRemoteViewPitch( Rotation.Pitch );
      }

      Pawn.Acceleration.X = -1 * PlayerInput.aStrafe * DeltaTime * 100 * PlayerInput.MoveForwardSpeed;
      Pawn.Acceleration.Y = 0;
      Pawn.Acceleration.Z = 0;
      
      tempRot.Pitch = Pawn.Rotation.Pitch;
      tempRot.Roll = 0;
      if(Normal(Pawn.Acceleration) Dot Vect(1,0,0) > 0)
      {
         tempRot.Yaw = 0;
         Pawn.SetRotation(tempRot);
      }
      else if(Normal(Pawn.Acceleration) Dot Vect(1,0,0) < 0)
      {
         tempRot.Yaw = 32768;
         Pawn.SetRotation(tempRot);
      }

      CheckJumpOrDuck();
   }
}
function UpdateRotation( float DeltaTime )
{
   local Rotator   DeltaRot, ViewRotation;

   ViewRotation = Rotation;
   DeltaRot.Yaw = Pawn.Rotation.Yaw;
   DeltaRot.Pitch   = PlayerInput.aLookUp;

   ProcessViewRotation( DeltaTime, ViewRotation, DeltaRot );
   SetRotation(ViewRotation);
}   
defaultproperties
{
}


Теперь идем в папку \UDK-20хх-хх\UDKGame\Config и открываем там файл DefaultEngine.ini и добавляем к строчкам
[UnrealEd.EditorEngine]
+EditPackages=UTGame
+EditPackages=UTGameContent 
свою +EditPackages=NewGames

чтоб получилось так:

+EditPackages=UTGame
+EditPackages=UTGameContent
+EditPackages=NewGames

Сохраняем все файлы и компилируем скрипты с помощью UnrealFrontend. Запускаем UDK editor и делаем простой уровень. Далее заходим в основном меню udk в View > World Properties и меняем на свой тип игры NewGamesInfo который должен появится в Game Type после компиляции скриптов.


Вот и все должно все работать.




Статья является переводом и правообладание на интеллектуальную собственность принадлежат  Epic Games, Inc. Использование статьи возможно только с указанием сайта первоисточника и сайта переводчика rusudk.ru

Комментариев нет:

Отправить комментарий

Примечание. Отправлять комментарии могут только участники этого блога.