Additional controls for custom vehicles

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

FlatSix

New Member
Dec 1, 2003
5
0
0
Hi all,

I'm trying to create a new vehicle (subclassed of KVehicle) with added custom controls, so that i'm not restricted to just throttle and steering. I've tried this by subclassing PlayerController and adding my own state (+code) to it. For now, i just used a copy of the code found in PlayerController. The whole stuff compiles but getting the controller in the disered state turns out to be a real pain. I tried various things in the KDriverEnter function (casting, etc.) but nothing seems to help. code changes resulted in (when entering vehicle) either controls freezing, becomes a flycam or become pinned to a fixed location (still able to turn and shoot, just not move). I followed the tutorial
http://wiki.beyondunreal.com/wiki/Alternative_Vehicle_Control
but i couldn't get that to work either. (same problem)

I fear that i'm doing something wrong with subclassing or assigning. I think modifying the playercontroller class directly is just a little bit too crude for me. Anyway, i've been at this for days, hours on end and its really driving me nuts!

Anybody have any ideas? Help is much appreciated!
 

FlatSix

New Member
Dec 1, 2003
5
0
0
I'll try to elaborate...

Ok, my objective is to create a new vehicle. My approach is to do this step-by-step, based off the bulldog.

So, my first step:
- created a copy of Bulldog.uc, BulldogFactory.uc, BulldogMessage, BulldogTrigger and KCar.
- Modified these files so their name is changed (Bulldog-> for example, MyCustomCar)
- modified the MyCustomCar.uc file, so it inherits from KMyCar instead of KCar
- Created a copy of VehicleDemo and placed a MyCustomCarFactory in it, bound to the existing trigger.
- Changed the mesh so i know for sure which vehicle is which.

So far so good! upon entering the game and touching the trigger, two vehicles fall from the sky. Namely, the bulldog and MyCustomCar, as expected. And works too :)

So now i have my own classes, derived from KVehicle and an implementation of it.

Now comes the tricky part. The vehicle is controlled by a PlayerController. The state is set to PlayerDriving, the code which handles this is in PlayerController.uc.

The big question is, how do I modify this, without changing the original PlayerController.uc. My best guess is to create a subclass of PlayerController (which i did) and add the relevant code there (for now just a copy of the PlayerDriving code from PlayerController).

Snippet:
function KDriverEnter(Pawn p)
{
local PlayerController pc;

// Set pawns current controller to control the vehicle pawn instead
Driver = p;

// Move the driver into position, and attach to car.
Driver.SetCollision(false, false, false);
Driver.bCollideWorld = false;
Driver.bPhysicsAnimUpdate = false;
Driver.Velocity = vect(0,0,0);
Driver.SetPhysics(PHYS_None);
Driver.SetBase(self);

pc = PlayerController(p.Controller);

// Disconnect PlyaerController from Driver and connect to KVehicle.
pc.Unpossess();
Driver.SetOwner(pc); // This keeps the driver relevant.
pc.Possess(self);

pc.ClientSetViewTarget(self); // Set playercontroller to view the vehicle

// Change controller state to driver
pc.GotoState('PlayerDriving');

ClientKDriverEnter(pc);
}

function TryToDrive(Pawn p)
{
local Controller C;
C = p.Controller;

if ( (Driver == None) && (C != None) && C.bIsPlayer && !C.IsInState('PlayerDriving') && p.IsHumanControlled() )
{
KDriverEnter(p);
}
}

I think this is where I need to change something, so that my customized controller takes over. This is where I'm doing most of my fiddling...

Concrete questions:
- Have i setup the MyCustomController class up correctly? Should it be derived from PlayerController? (or maybe something like UnrealPlayer or xPlayer?)
- Am I looking in the right place to change the controller state? Do any other things need to be changed, like variable types (local PlayerController pc; isn't going to work i guess)?
- Maybe other classes need to be customized first, which i completely overlooked?

Whew, that question got big ;-)

Thanks for the help!
 

[SAS]Solid Snake

New Member
Jun 7, 2002
2,633
0
0
40
New Zealand
www.digitalconfectioners.com
Your on the right path. Make your own xDeathmatch subclass which will allow you then to set what the player's controller will be, which will be your custom one.
Subclass of xPlayer, and have your own PlayerDriving state in there.

When you hop in the car it will use the PlayerDriving from the PlayerController that the player is using.

Don't worry too much about changing the PlayerController variables since the controller is still a player controller.
 

FlatSix

New Member
Dec 1, 2003
5
0
0
Great! I tried it, and it works! I created a new state though, so i can still ride the bulldog ;)

Anyway, Thanks for the help! :)