class RPGPawn extends UDKPawn;
/*********************************************************************************************
* Foot placement IK system
********************************************************************************************* */
var name LeftFootBone, RightFootBone;
var name LeftFootControlName, RightFootControlName;
var float BaseTranslationOffset;
var float CrouchTranslationOffset;
var float OldLocationZ;
var bool bEnableFootPlacement;
var const float ZSmoothingRate;
/** if the pawn is farther than this away from the viewer, foot placement is skipped */
var float MaxFootPlacementDistSquared;
/** cached references to skeletal controllers for foot placement */
var SkelControlFootPlacement LeftLegControl, RightLegControl;
/******************************************************************************
Propiedades del Apuntado
******************************************************************************/
var AnimNodeAimOffset RPGAimNode; // Referencia al nodo de animación de AimOffset
var Rotator DesiredAim; // Aim deseado
var Rotator CurrentAim; // Aim actual
var float AimSpeed; // Velocidad de apuntado
/******************************************************************************
Propiedades del SkeletalMesh
******************************************************************************/
var const SkeletalMeshComponent ArmsSkeletalMesh;
var const SkeletalMeshComponent BootsSkeletalMesh;
/* Iluminación de entorno */
var DynamicLightEnvironmentComponent LightEnvironment;
/******************************************************************************
Propiedades de Cámara
******************************************************************************/
var vector DesiredCamStartLocation; // Posición deseada desde la que se hace el offset (Posición del Pawn)
var vector DesiredCamOffset; // Offset deseado de la cámara
var float DesiredCamScale; // CameraScale deseado
var float DesiredCamZOffset; // Offset en z de la cámara (añadido al offset de cámara)
var vector CurrentCamStartLocation; // Posición actual desde la que se hace el offset
var vector CurrentCamOffset; // Offset actual interpolado de la cámara
var float CurrentCamScale; // Se usa para interpolar entre distintos CameraScales
var float CurrentCamZOffset; // Usado para interpolar el offset en z de la cámara
var vector CamOffsetDefault; // Offset de postura Default
var vector CamOffsetAimRight; // Offset de postura AimRight
var float CameraInterpolationSpeed; //Velocidad de interpolación
// Posturas para disparo y aiming:
enum PawnWeaponType
{
PWT_Default,
PWT_AimRight
};
var PawnWeaponType WeaponType; // Postura actual
// Cambia el tipo de Weapon, cambiando así la postura
function SetWeaponType(PawnWeaponType NewWeaponType)
{
WeaponType = NewWeaponType;
}
// Cambia al arma por defecto
function SetDefaultWeaponType()
{
SetWeaponType(PWT_Default);
}
// Sobreescribe una función para que se vea al pawn por defecto
// La llama la Camara cuando este actor se convierte en su ViewTarget
simulated event BecomeViewTarget( PlayerController PC )
{
local UTPlayerController UTPC;
// Por defecto esta llamada pone los brazos al Pawn y el arma inicial (y otras cosas)
Super.BecomeViewTarget(PC);
if (LocalPlayer(PC.Player) != None)
{
UTPC = UTPlayerController(PC);
if (UTPC != None)
{
// Activa la vista trasera (Poner la camara en tercera persona y hace desaparecer brazos y armas de primera persona
UTPC.SetBehindView(true);
// Esto no es necesario
//SetMeshVisibility(UTPC.bBehindView);
}
}
}
// Función que calcula la posición de la cámara
// Es un ripoff de la función CalcThirdPersonCam de UTPawn, quitando los casos de DebugCam o cuado se gana la partida
simulated function bool CalcCamera( float fDeltaTime, out vector out_CamLoc,
out rotator out_CamRot, out float out_FOV )
{
local vector HitLocation, HitNormal, CamDirX, CamDirY, CamDirZ;
// Valores deseados:
DesiredCamStartLocation = Location; // El punto inicial de la cámara es la posición del Pawn
if(WeaponType == PWT_AimRight) // Offset varía según postura (tipo de arma)
{
DesiredCamOffset = CamOffsetAimRight;
}
else
{
DesiredCamOffset = CamOffsetDefault;
}
DesiredCamZOffset = (Health > 0) ? 1.0 * GetCollisionHeight() + Mesh.Translation.Z : 0.f;
// Valores interpolados:
CurrentCamStartLocation = VLerp(CurrentCamStartLocation, DesiredCamStartLocation, CameraInterpolationSpeed*fDeltaTime);
CurrentCamOffset = VLerp(CurrentCamOffset, DesiredCamOffset, CameraInterpolationSpeed*fDeltaTime);
CurrentCamScale = Lerp(CurrentCamScale, DesiredCamScale, CameraInterpolationSpeed*fDeltaTime);
CurrentCamZOffset = Lerp(CurrentCamZOffset, DesiredCamZOffset, CameraInterpolationSpeed*fDeltaTime);
if ( Health <= 0 )
{
CurrentCamOffset = vect(0,0,0);
CurrentCamOffset.X = GetCollisionRadius();
}
// Se extraen los ejes de la rotación de la cámara
GetAxes(out_CamRot, CamDirX, CamDirY, CamDirZ);
// Escala de la camara (zoom)
CamDirX *= CurrentCamScale;
if ( (Health <= 0) || bFeigningDeath )
{
// adjust camera position to make sure it's not clipping into world
// @todo fixmesteve. Note that you can still get clipping if FindSpot fails (happens rarely)
FindSpot(GetCollisionExtent(),CurrentCamStartLocation);
}
// Cálculo de la posición final de la cámara
out_CamLoc = (CurrentCamStartLocation + vect(0.0,0.0,1.0) * CurrentCamZOffset) - CamDirX*CurrentCamOffset.X + CurrentCamOffset.Y*CamDirY + CurrentCamOffset.Z*CamDirZ;
// Se traza un rayo para calcular posibles colisiones con la geometría
if (Trace(HitLocation, HitNormal, out_CamLoc, CurrentCamStartLocation, false, vect(12,12,12)) != None)
{
out_CamLoc = HitLocation;
}
return true;
}
/******************************************************************************
Propiedades del Apuntado
******************************************************************************/
simulated event PostInitAnimTree(SkeletalMeshComponent SkelComp)
{
// Se busca la referencia del nodo de Aiming
RPGAimNode = AnimNodeAimOffset(SkelComp.FindAnimNode('RPGAimNode'));
}
simulated event Destroyed()
{
Super.Destroyed();
RPGAimNode = None; //Es necesario desreferenciar el nodo para que el Pawn se destruya correctamente
}
simulated function Tick(float DeltaTime)
{
Super.Tick(DeltaTime);
// Se obtiene la rotación actual del controller y se clampea con el max y min
DesiredAim = GetBaseAimRotation();
DesiredAim.Pitch = Clamp(DesiredAim.Pitch, ViewPitchMin, ViewPitchMax);
// Interpolación de la rotación
if (DesiredAim != CurrentAim)
{
CurrentAim = RLerp(CurrentAim, DesiredAim, AimSpeed * DeltaTime, false);
}
// Se cambia el nodo de animación
if (CurrentAim.Pitch < 0)
{
RPGAimNode.Aim.Y = -float(CurrentAim.Pitch) / ViewPitchMin;
}
else if (CurrentAim.Pitch > 0)
{
RPGAimNode.Aim.Y = float(CurrentAim.Pitch) / ViewPitchMax;
}
else
{
RPGAimNode.Aim.Y = 0.f;
}
}
// Sobreescribe la funcion de Pawn
function AddDefaultInventory()
{
// Se le da al Pawn el arma al comenzar
InvManager.CreateInventory(class'MyRPG.RPGWeapon1',true); // No activar por defecto
InvManager.CreateInventory(class'MyRPG.RPGWeapon2',true);
}
// Cambio de arma, llamado desde RPGPlayerController
simulated function SwitchWeapon(byte NewGroup)
{
if (RPGInventoryManager(InvManager) != None)
{
// Se le indica al Manager del Inventario que cambie de arma
RPGInventoryManager(InvManager).SwitchWeapon(NewGroup);
}
}
simulated event PostInitAnimTree(SkeletalMeshComponent SkelComp)
{
if (SkelComp == Mesh)
{
LeftLegControl = SkelControlFootPlacement(Mesh.FindSkelControl(LeftFootControlName));
RightLegControl = SkelControlFootPlacement(Mesh.FindSkelControl(RightFootControlName));
}
super.PostInitAnimTree(SkelComp);
}
defaultproperties
{
// Iluminación de entorno del Pawn
// Iluminacion de entorno del Pawn
Begin Object Class=DynamicLightEnvironmentComponent Name=MyLightEnvironment
bSynthesizeSHLight=false
bIsCharacterLightEnvironment=false
bUseBooleanEnvironmentShadowing=FALSE
InvisibleUpdateTime=1
MinTimeBetweenFullUpdates=.2
End Object
Components.Add(MyLightEnvironment)
LightEnvironment=MyLightEnvironment
// Componente SkeletalMesh para el robot
Begin Object Class=SkeletalMeshComponent Name=TORSO
SkeletalMesh=SkeletalMesh'Dario.Human.Human_M_H00_Body_Skel'
LightEnvironment=MyLightEnvironment
AnimSets(0)=AnimSet'Dario.Human.Human_M_H00_Body_Skel_Anims'
AnimTreeTemplate=AnimTree'Dario.Human.Human_M_H00_Body_Skel_Tree'
PhysicsAsset=PhysicsAsset'Dario.Human.Human_M_H00_Body_Skel_Physics'
End Object
Mesh=TORSO
Components.Add(TORSO)
Begin Object Class=SkeletalMeshComponent Name=Boots
LightEnvironment=MyLightEnvironment
SkeletalMesh=SkeletalMesh'Dario.Human.Human_M_H00_Leg_Skel'
ParentAnimComponent=TORSO
ShadowParent=TORSO
End Object
BootsSkeletalMesh=Boots
Components.Add(Boots)
Begin Object Class=SkeletalMeshComponent Name=Arms
LightEnvironment=MyLightEnvironment
SkeletalMesh=SkeletalMesh'Dario.Human.Human_M_H00_Hand_Skel'
ParentAnimComponent=TORSO
ShadowParent=TORSO
End Object
ArmsSkeletalMesh=Arms
Components.Add(Arms
// Se hace más pequeño el cilindro de colisión
Begin Object Name=CollisionCylinder
CollisionRadius=+0010.000000
CollisionHeight=+26.600000
End Object
CylinderComponent=CollisionCylinder
//El robot es un poco grande
DrawScale=0.8
//Velocidad de Animacion dentro del mapa
GroundSpeed=105
//Velocidad al Apuntar
AimSpeed=8
LeftFootControlName=LeftFootControl
RightFootControlName=RightFootControl
bEnableFootPlacement=true
MaxFootPlacementDistSquared=56250000.0 // 7500 squared
// Propiedades de cámara
DesiredCamScale=20.0
CurrentCamScale=0.0
CameraInterpolationSpeed=8.0 //Velocidad de interpolación de la cámara
CamOffsetDefault=(X=4.0,Y=0.0,Z=-13.0) // Offset postura default
CamOffsetAimRight=(X=4.0,Y=40.0,Z=-13.0) // Offset postura RightAim
//Locomoción
JumpZ=+0600.000000
MaxFallSpeed=+1200.0 //Máxima velocidad al caer sin hacerse daño
AirControl=+0.1 //Control aéreo
CustomGravityScaling=1.3 //Multiplicador de gravedad personal
InventoryManagerClass=class'MyRPG.RPGInventoryManager'
}