UE3 - UDK How do I move a pawn using its built-in functions/animations?

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

Nathaniel3W

Member
Nov 11, 2012
48
0
6
I've got this working so far. It creates an object that represents my physical gaming controller (a Razer Hydra), gets data from the controller, and then turns and moves my pawn.

Code:
classMyUnrealGame01PlayerController extends GamePlayerController;
var sixense TheSixense;

defaultproperties
{
   CameraClass=class'MyUnrealGame01.MyUnrealGame01Camera'
   InputClass=class'MyUnrealGame01.MyUnrealGame01PlayerInput'
}

simulated event PostBeginPlay()
{
	super.PostBeginPlay();
	TheSixense = new class'Sixense';
	TheSixense.sixenseInit();
	TheSixense.sixenseGetAllNewestData(TheSixense.TheControllerData);
}

simulated event PlayerTick(float DeltaTime)
{
	local vector LeftJoystick;
	local rotator RightJoystick;
	super.Tick(DeltaTime);
	TheSixense.sixenseGetAllNewestData(TheSixense.TheControllerData);
	RightJoystick.Yaw = Pawn.Rotation.Yaw + TheSixense.TheControllerData.controller[0].joystick_x * DeltaTime * 4000;
	RightJoystick.Pitch = Pawn.Rotation.Pitch + TheSixense.TheControllerData.controller[0].joystick_y * DeltaTime * 4000;
	RightJoystick.Roll = Pawn.Rotation.Roll;
	Pawn.SetRotation(RightJoystick);
	LeftJoystick.X = -TheSixense.TheControllerData.controller[1].joystick_x * DeltaTime * 100;
	LeftJoystick.Y = TheSixense.TheControllerData.controller[1].joystick_y * DeltaTime * 100;
	Pawn.Move(LeftJoystick);
}

But as you can probably tell, that code just slides the pawn around on an absolute X,Y plane, and the movement is not relative to the pawn's facing. It also doesn't play the running animation. It's doesn't take into account acceleration or the pawn's ground or water speed. And the pitch and roll will rotate the pawn, but not the camera.

I'm sure I could do the trigonometry on my own to change the model facing and the camera together, then translate my joystick's absolute X,Y into the model's relative X,Y. But I'm sure I would be reinventing the wheel.

Can anyone recommend some reading on how to take my joystick input and make it change the model's direction, move the model relative to its rotation, move the camera with the model, and play the appropriate animations? There have to be functions already written for that, right?
 
Last edited:

Nathaniel3W

Member
Nov 11, 2012
48
0
6
Answering my own question here. And if anyone else has the same question, here's the answer: Just copy everything from PlayerController.uc's PlayerTick event and PlayerWalking state into your own extension of PlayerController, and make whatever changes are necessary to take input from whatever device you're adding functionality from. The standard value of PlayerInput.aForward (and related variables) is about 2000, so keep that in mind when you're choosing multipliers for your acceleration.