Unreal Script - Sprinting and Crouching
Anyone who has played a first person shooter game knows the importance of sprinting and crouching – in some cases, it’s the difference between getting shot and not. In theory, setting up a sprint or crouch function in the UDK is quite simple – you basically need to change the speed/height of the pawn while a key is pressed (or on a toggle if the player desires)
Fortunately, the UDK already includes a “crouch” function, which is horribly (in my opinion) bound to ‘C’ – I know, most people like this, I prefer Left CTRL. So to fix it in my bindings, I needed to change
.Bindings=(Name="LeftControl",Command="GBA_Jump")
to read
.Bindings=(Name="LeftControl",Command="GBA_Duck")
For sprinting, this is a little more involved, as most games employ a mechanic that allows a player to tire when running – additionally, a player cannot fire while running as they’d spray bullets everywhere. In effect, this is really simple to do, and involves adding the following to your Pawn class (which I assume you have already extended from UTPawn)
//Sprint handling variables
var float SprintSpeed;
var float WalkSpeed;
var float Stamina;
var float SprintTimer;
var float SprintRecoverTimer;
var float Empty;
var bool bSprinting;
exec function startSprint()
{
GroundSpeed = SprintSpeed;
bSprinting = true;
if(GroundSpeed == SprintSpeed)
{
StopFiring();
setTimer(SprintTimer, false, 'EmptySprint');
}
}
exec function stopSprint()
{
GroundSpeed = WalkSpeed;
}
simulated function EmptySprint()
{
Stamina = Empty;
GroundSpeed = WalkSpeed;
bSprinting = true;
setTimer(SprintRecoverTimer, false, 'ReplenishStamina');
}
simulated function ReplenishStamina()
{
Stamina = 10.0;
bSprinting = false;
}
defaultproperties
{
GroundSpeed=200.0
AirSpeed=200.0
//Overrides for Zombies game
WalkSpeed=280.0
SprintSpeed=500.0
SprintTimer=6.0
SprintRecoverTimer=4.0
Stamina=6.0
Empty=1
}
This relies on a key binding change in the DefaultInput.ini file, where you can add this line:
.Bindings=(Name="LeftShift",Command="StartSprint | OnRelease StopSprint")
Once compiled, you can hold the Left Shift key to sprint, or Left Control to crouch. This example is pretty noticeable, mainly as I don’t have any animations for my first person weapons, but if you do, just change the SprintSpeed and WalkSpeed properties to whatever you like and see the difference.
0 comentários:
Postar um comentário
Seu comentário é importante para a manutenção do BLOG.
Não será publicado comentários que infringirem as seguintes regras:
01- ofensas gratuitas aos membros da UDKBrasil
02- descrédito para com a postagem
03- links com malwares ou qualquer tipo de fraude
04- palavras de baixo calão contra participantes
05- links de download não serão permitidos, a não ser que sejam gratuitos (freeware ou software de teste) e relacionados a UDK ou Computação Grafica.
Pedimos a gentileza de não USAR CAPS LOCK ligado.
OBS; assim que seu comentário for publicado,se junto dele NÃO houver uma resposta para sua dúvida,é porque não sabemos te responder...infelizmente, não sabemos de tudo!!
Seja bem vindo.