How to Dynamicaly change the Player Pawn.
Put this in your Player Controller. The example here is using an 'exec' function so it can be triggered from a button press or console command.
Put this in your Player Controller. The example here is using an 'exec' function so it can be triggered from a button press or console command.
exec function FPress() { //declare the variables local pawn p; local vector l; local rotator r; //set the variables p = Pawn; l = Pawn.Location; r = Pawn.Rotation; // get rid of the old pawn UnPossess(); p.Destroy(); //spawn a new pawn and possess it p = Spawn(class'SomePawnClass', , ,l,r); //use false if you spawned a character and true for a vehicle Possess(p, false); }
I get an error at
ReplyDeletep = Spawn(class'name', , ,l,r);
i tried using class'UTPawn', but i get same error.
Bar or missing experssion in "="
change this variable to whatever class your using
ReplyDeletelocal pawn p;
if you use UTPawn
local UTPawn p;
what if you wanted to possess a pawn already in the level? (rather than Spawn()) ?
ReplyDeleteyou can do it simply by using the controller class and call:
DeletePossess(Pawn, bool); //call unpossess before aswell.
to spawn a character in front of your character, you could do something as storing your offset, and then use the function getAxes.
Just multiply the different axis with ur offset. Think that'll do it =).
you need to get a reference to the said pawn and possess it.
ReplyDeletesorry its been a while, but ive come back to this, how do you actually reference a pawn in the level?
ReplyDeleteive never done this before - grabbing a variable from the current level to pass through some script
hi again, if you want a character to Spawn infront of the character how do i do this?
ReplyDeleteim doing a side scroller
at the moment i have:
----------------------
local Vector PLoc;
local Pawn Player2;
PLoc = Pawn.Location; //player1
PLoc.X = (Pawn.Location.X + 40);
Player2 = spawn(class'Player2', , ,PLoc,);
--------------
this obviously just sticks the new player at +40 from the pawn along the X regardless of which was he is facing
how do i change that so its always infront of him with which way he is facing?
This comment has been removed by the author.
ReplyDeleteVery useful - thanks for posting this!
ReplyDeleteI've written a variant that accepts a string className as an argument, but unfortunately can't paste it intact here (angle braces get interpreted as html).
To make the following code usable, correct the declaration of the NewClass variable:
local class(actor) NewClass;
// replace the parens with angle braces, and fix the NewClass assignment:
NewClass = class(actor)(DynamicLoadObject(ClassName, class'Class'));
again replacing the parens around actor with angel braces.
/**
* Removes this controller from the existing pawn and possesses a new one. (exec)
*
* @param ClassName The classname of the WMPawn to possess
*/
exec function ChangePawn(string ClassName)
{
local Pawn P;
local Vector PawnLocation;
local Rotator PawnRotation;
local class NewClass;
P = Pawn;
PawnLocation = Pawn.Location;
PawnRotation = Pawn.Rotation;
NewClass = class(DynamicLoadObject(ClassName, class'Class'));
// Detach the current pawn from this controller and destroy it.
UnPossess();
P.Destroy();
//spawn a new pawn and attach this controller
P = Pawn(Spawn(NewClass, , ,PawnLocation,PawnRotation));
//use false if you spawned a character and true for a vehicle
Possess(P, false);
}
I'm trying to get this hooked up when I Possess one of two pawns that will already be spawned inside the level. Basically, what I want is to be able to possess either of the spawned "hosts", destroy the default pawn ("ghost"), the Unpossess the host, thus destroying the host pawn and respawning the ghost. I have Possess and Dispossess functions working without this code, but I've been able to get it working fundamentally (though it's mapped to a separate input) to allow the Host body to be destroyed and respawn the Ghost pawn.
ReplyDeleteI'd greatly appreciate any guidance you're able to give.
Thank you so much this helped a lot with my game. :3
ReplyDelete