PDA

View Full Version : Need help with Controllers (and pawns)


CiberX15
6th Oct 2008, 11:46 AM
Ok I hope I don’t sound like too much of an idiot. I am trying to create a very simple NPC, I mean I want him to do nothing but walk forwards. I have a pawn and I think I have some idea of how a controller works, but how do you tell a pawn what controller to use? If someone could tell me how, or better yet send me an example so I can see it work I would be very grateful.

Thanks

Angel_Mapper
6th Oct 2008, 01:01 PM
If nobody answers you by tonight I'll post up some of my Tamearia code when I get home.

CiberX15
7th Oct 2008, 09:29 AM
ok thanks

Angel_Mapper
7th Oct 2008, 03:54 PM
The Pawn class:
class TameariaCitizenPawn extends Pawn;

var(Tamearia) edfindable PawnPathController InitialPathController;

simulated function PostBeginPlay()
{
super.PostBeginPlay();

AssignInitialPose();
SetPhysics(PHYS_Walking);
}

defaultproperties
{
ControllerClass=Class'Tamearia.TameariaCitizen'
}

The Controller:
class TameariaCitizen extends AIController;

var PawnPathController CurrentPathController;
var int CurrentPathPointNum, CurrentPathNum;

function Possess(Pawn aPawn)
{
super.Possess(aPawn);
if(TameariaCitizenPawn(aPawn) != none && TameariaCitizenPawn(aPawn).InitialPathController != none)
{
CurrentPathController = TameariaCitizenPawn(aPawn).InitialPathController;
SetTimer(CurrentPathController.PauseHereTime,false);
}
}


function Timer()
{
if(CurrentPathController.Paths.Length > 0)
CurrentPathNum = Rand(CurrentPathController.Paths.Length);
else
CurrentPathNum = -1;
CurrentPathPointNum = 0;

if(Pawn != none)
Pawn.SetPhysics(PHYS_Walking);
GoToState('Moving');
}

state WaitingToMove
{
function PlayerWantsToTalk()
{
PreviousState = 'WaitingToMove';
GoToState('InteractingWithPlayer');
}

Begin:
SetTimer(CurrentPathController.PauseHereTime,false);
}

state Idle
{
Begin:
MoveTo(Pawn.Location);
}

state Moving
{
function SetMoveTarget()
{
local Actor NextMoveTarget;

if(CurrentPathPointNum < CurrentPathController.Paths[CurrentPathNum].PathPoints.Length)
NextMoveTarget = CurrentPathController.Paths[CurrentPathNum].PathPoints[CurrentPathPointNum].Point;
else
GoToState('WaitingToMove');

if ( NextMoveTarget == None )
{
CurrentPathController = CurrentPathController.Paths[CurrentPathNum].PathEndController;
CurrentPathPointNum = 0;
GoToState('WaitingToMove');
return;
}
MoveTarget = NextMoveTarget;
}

Begin:
SetMoveTarget();
if ( (MoveTarget != None) && (MoveTarget != Pawn) )
{
MoveToward(MoveTarget,,,,True);
Focus = none;
if ((MoveTarget != CurrentPathController.Paths[CurrentPathNum].PathPoints[CurrentPathPointNum].Point)
|| !Pawn.ReachedDestination(CurrentPathController.Paths[CurrentPathNum].PathPoints[CurrentPathPointNum].Point))
Goto('Begin');
}
CurrentPathPointNum++;
Goto('Begin');
}

defaultproperties
{
}


And the PathController (a custom actor):

class PawnPathController extends TameariaObject
placeable;

struct PathPoint
{
var() edfindable Actor Point;
};

struct Path
{
var() edfindable array<PathPoint> PathPoints;
var() edfindable PawnPathController PathEndController;
var() int Weight;
};
var() array<Path> Paths;
var() int PauseHereTime;

DefaultProperties
{
bNoDelete=False
}

So with this code you'd place the TameariaCitizenPawn, then place a PawnPathController and put it in the TameariaCitizenPawn's properties. In the PathController you can make a bunch of different paths, then add nodes to those paths, and pass the pawn off to a different PawnPathController once it reaches the end of that path. If you just want it to walk forward just add one path.

Let me know if you have any problems with the code, I snipped out the irrelevant bits but I could have missed something.

CiberX15
8th Oct 2008, 08:29 AM
Thank you so much

CiberX15
8th Oct 2008, 09:13 AM
I am using the UMake compiler and it keeps giving me error mesages saying it can't rebuild the package because the code is bad. "AssignInitialPose();" in the pawn and "PreviousState" in the controller seem to be causing the problems they seem right to me but I don't know a lot about unreal code yet. I don't think the unreal engine likes me :(

Angel_Mapper
8th Oct 2008, 12:56 PM
Just take out the AssignInitialPose line and the entire PlayerWantsToTalk function, I missed those.

CiberX15
8th Oct 2008, 03:01 PM
Ok, everything is compileing now, thanks a lot. :)

CiberX15
8th Oct 2008, 09:03 PM
problem, when I actualy play the game my pawn just stands there. its almost like he's still not using controller, more as I mess with it. I did mess with the script to adapt it to the characters that I already had in place, but all I did was change a few names so it called the right actors. Though I'm new to unreal script I do know python and basic so I'm not compleatly clueless but this is a tough little bugger.

cpnineteen
21st Oct 2008, 10:50 AM
I am having the same problem and when i started from scratch i just used the same names and it still isnt working so im not sure what to do any help would be appreciated but i cant see from the code what isnt working