Wednesday, October 3, 2012

Cookbook: UDK set of objects instead of a Pawn

Normally, UDK is mainly a framework for first/third person shooter games. Many things are hardcoded, like necessity to have a Pawn as you main character (or references to UT3 in DefaultEngine.ini). For smaller (indie) projects that is many times not desired. What if you want to be able to control a simple KActor or some set of objects (like chess pieces)? That is not a problem!

insert instances of desired objects into scene (I'm controlling one actor):

collect references to your objects in some early phase:

   1:  var MyActorClass MyActor
   3:  simulated event PostBeginPlay()
   4:  {
   5:      super.PostBeginPlay(); //call parent
   7:      //iterate through all actors of given class and store them!
   8:      foreach WorldInfo.DynamicActors(class'MyActorClass', MyActor)
   9:      {
  10:          //some additional init?
  11:          Init();
  12:          break; //if interested only in first one
  13:      }
  14:  }

override Pawn dependent behavior in your custom classes to work with your actors (example from custom 3rd person camera):

   1:  class MyCamera extends Camera;
   3:  //override, use your actor as the point of interest for camera
   4:  function UpdateViewTarget(out TViewTarget OutVT, float DeltaTime)
   5:  {
   6:      super.UpdateViewTarget(OutVT,DeltaTime);
   8:      //add some offset to the target's for 3rd person camera
   9:      OutVT.POV.Location = MyActor.Location + Properties.CamOffset;
  11:      // Make the camera point towards the target's location
  12:      OutVT.POV.Rotation = Rotator(MyActor.Location - OutVT.POV.Location);
  13:  }

1 comment:

  1. Could you elaborate on some more things to override? I am struggling to get my playercontroller to play nice with my actor "character".