Need help with Controllers (and pawns)

  • 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.

CiberX15

New Member
Oct 5, 2008
26
0
0
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

Goooooooats
Jun 17, 2001
3,532
3
38
Cape Suzette
www.angelmapper.com
The Pawn class:
Code:
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:
Code:
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):

Code:
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

New Member
Oct 5, 2008
26
0
0
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 :(
 

CiberX15

New Member
Oct 5, 2008
26
0
0
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.
 
Last edited:

cpnineteen

New Member
Sep 9, 2008
1
0
0
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