PDA

View Full Version : Dying camera and player physics



MaVmAn
11-05-2010, 12:10 PM
Hello,
I'm trying to have a simple "camera effect" when the player die.
Something very simple like in HL: the camera just fall down on the ground.

I'm not very experienced with uScript so I get stuck...
Here what I did:

-My Pawn is based on UTPawn, so I removed the mesh (as I don't need it and as it's not allowed for commercial game to use SkeletalMesh and will be a waste of time to make my own one) by "blank" overwriting "SetCharacterMeshInfo" function and setting "Components.Remove(WPawnSkeletalMeshComponent)" in default properties.
I don't know if it's the proper way, certainly not...

-Blank Overwritten "simulated function bool CalcThirdPersonCam". Seems useless, I guess it's not used for dying view.

-Overwritten "simulated function PlayDying": I just changed "PlayersRagdoll = true;" to false and "CollisionComponent = Mesh;" to "CollisionComponent = CollisionComponent;"


So the result seems almost good, except I have a weird rotating camera some seconds before going back to the first person view,when waiting for respawn.
The camera is also a bit far from the ground and don't slide when player die on a slope.

Is there someone who know how to always stay in first person view when die and have the camera reacting like a rigidbody, falling on the ground and slide on slope (this last point is not a priority just will be nicer...) ?

Here the Pawn code:


Class NE_Pawn extends UTPawn;


/** REMOVE & OVERWRITTED FUNCTIONS */
//************************************************** ************************************************** ***************************/

exec simulated function FeignDeath() {} //Remove feignDeath

function bool Dodge(eDoubleClickDir DoubleClickMove) //Remove Dodge
{
return false;
}

simulated function SetFirstPersonArmsInfo(SkeletalMesh FirstPersonArmMesh, MaterialInterface ArmMaterial) {} //Remove arms mesh

simulated function bool CalcThirdPersonCam( float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV ) {} //Remove dead rotating cam TEST, Not Working

simulated function SetCharacterMeshInfo(SkeletalMesh SkelMesh, MaterialInterface HeadMaterial, MaterialInterface BodyMaterial) {} //Remove mesh TEST




//************************************************** ************************************************** ***************************/


/** -----------------------------------TEST----------------------------------*/

/**
* Responsible for playing any death effects, animations, etc.
*
* @param DamageType - type of damage responsible for this pawn's death
*
* @param HitLoc - location of the final shot
*/
simulated function PlayDying(class<DamageType> DamageType, vector HitLoc)
{
local vector ApplyImpulse, ShotDir;
local TraceHitInfo HitInfo;
local PlayerController PC;
local bool bPlayersRagdoll, bUseHipSpring;
local class<UTDamageType> UTDamageType;
local RB_BodyInstance HipBodyInst;
local int HipBoneIndex;
local matrix HipMatrix;
local class<UDKEmitCameraEffect> CameraEffect;
local name HeadShotSocketName;
local SkeletalMeshSocket SMS;

bCanTeleport = false;
bReplicateMovement = false;
bTearOff = true;
bPlayedDeath = true;
bForcedFeignDeath = false;
bPlayingFeignDeathRecovery = false;

HitDamageType = DamageType; // these are replicated to other clients
TakeHitLocation = HitLoc;

// make sure I don't have an active weaponattachment
CurrentWeaponAttachmentClass = None;
WeaponAttachmentChanged();

if ( WorldInfo.NetMode == NM_DedicatedServer )
{
UTDamageType = class<UTDamageType>(DamageType);
// tell clients whether to gib
bTearOffGibs = (UTDamageType != None && ShouldGib(UTDamageType));
bGibbed = bGibbed || bTearOffGibs;
GotoState('Dying');
return;
}

// Is this the local player's ragdoll?
ForEach LocalPlayerControllers(class'PlayerController', PC)
{
if( pc.ViewTarget == self )
{
if ( UTHud(pc.MyHud)!=none )
UTHud(pc.MyHud).DisplayHit(HitLoc, 100, DamageType);
//bPlayersRagdoll = true; //--------------------------------------TEST
bPlayersRagdoll = false;
break;
}
}
if ( (WorldInfo.TimeSeconds - LastRenderTime > 3) && !bPlayersRagdoll )
{
if (WorldInfo.NetMode == NM_ListenServer || WorldInfo.IsRecordingDemo())
{
if (WorldInfo.Game.NumPlayers + WorldInfo.Game.NumSpectators < 2 && !WorldInfo.IsRecordingDemo())
{
Destroy();
return;
}
bHideOnListenServer = true;

// check if should gib (for clients)
UTDamageType = class<UTDamageType>(DamageType);
if (UTDamageType != None && ShouldGib(UTDamageType))
{
bTearOffGibs = true;
bGibbed = true;
}
TurnOffPawn();
return;
}
else
{
// if we were not just controlling this pawn,
// and it has not been rendered in 3 seconds, just destroy it.
Destroy();
return;
}
}

UTDamageType = class<UTDamageType>(DamageType);
if (UTDamageType != None && !class'UTGame'.static.UseLowGore(WorldInfo) && ShouldGib(UTDamageType))
{
SpawnGibs(UTDamageType, HitLoc);
}
else
{
CheckHitInfo( HitInfo, Mesh, Normal(TearOffMomentum), TakeHitLocation );

// check to see if we should do a CustomDamage Effect
if( UTDamageType != None )
{
if( UTDamageType.default.bUseDamageBasedDeathEffects )
{
UTDamageType.static.DoCustomDamageEffects(self, UTDamageType, HitInfo, TakeHitLocation);
}

if( UTPlayerController(PC) != none )
{
CameraEffect = UTDamageType.static.GetDeathCameraEffectVictim(sel f);
if (CameraEffect != None)
{
UTPlayerController(PC).ClientSpawnCameraEffect(Cam eraEffect);
}
}
}

bBlendOutTakeHitPhysics = false;

// Turn off hand IK when dead.
SetHandIKEnabled(false);

// if we had some other rigid body thing going on, cancel it
if (Physics == PHYS_RigidBody)
{
//@note: Falling instead of None so Velocity/Acceleration don't get cleared
setPhysics(PHYS_Falling);
}

PreRagdollCollisionComponent = CollisionComponent;
//CollisionComponent = Mesh; //--------------------------------------------------------------TEST
CollisionComponent = CollisionComponent; //---------------------------------------------------------------TEST

Mesh.MinDistFactorForKinematicUpdate = 0.f;

// If we had stopped updating kinematic bodies on this character due to distance from camera, force an update of bones now.
if( Mesh.bNotUpdatingKinematicDueToDistance )
{
Mesh.ForceSkelUpdate();
Mesh.UpdateRBBonesFromSpaceBases(TRUE, TRUE);
}

Mesh.PhysicsWeight = 1.0;

if(UTDamageType != None && UTDamageType.default.DeathAnim != '' && (FRand() > 0.5) )
{
// Don't want to use stop player and use hip-spring if in the air (eg PHYS_Falling)
if(Physics == PHYS_Walking && UTDamageType.default.bAnimateHipsForDeathAnim)
{
SetPhysics(PHYS_None);
bUseHipSpring=true;
}
else
{
SetPhysics(PHYS_RigidBody);
// We only want to turn on 'ragdoll' collision when we are not using a hip spring, otherwise we could push stuff around.
SetPawnRBChannels(TRUE);
}

Mesh.PhysicsAssetInstance.SetAllBodiesFixed(FALSE) ;

// Turn on angular motors on skeleton.
Mesh.bUpdateJointsFromAnimation = TRUE;
Mesh.PhysicsAssetInstance.SetNamedMotorsAngularPos itionDrive(false, false, NoDriveBodies, Mesh, true);
Mesh.PhysicsAssetInstance.SetAngularDriveScale(1.0 f, 1.0f, 0.0f);

// If desired, turn on hip spring to keep physics character upright
if(bUseHipSpring)
{
HipBodyInst = Mesh.PhysicsAssetInstance.FindBodyInstance('b_Hips ', Mesh.PhysicsAsset);
HipBoneIndex = Mesh.MatchRefBone('b_Hips');
HipMatrix = Mesh.GetBoneMatrix(HipBoneIndex);
HipBodyInst.SetBoneSpringParams(DeathHipLinSpring, DeathHipLinDamp, DeathHipAngSpring, DeathHipAngDamp);
HipBodyInst.bMakeSpringToBaseCollisionComponent = FALSE;
HipBodyInst.EnableBoneSpring(TRUE, TRUE, HipMatrix);
HipBodyInst.bDisableOnOverextension = TRUE;
HipBodyInst.OverextensionThreshold = 100.f;
}

FullBodyAnimSlot.PlayCustomAnim(UTDamageType.defau lt.DeathAnim, UTDamageType.default.DeathAnimRate, 0.05, -1.0, false, false);
SetTimer(0.1, true, 'DoingDeathAnim');
StartDeathAnimTime = WorldInfo.TimeSeconds;
TimeLastTookDeathAnimDamage = WorldInfo.TimeSeconds;
DeathAnimDamageType = UTDamageType;
}
else
{
SetPhysics(PHYS_RigidBody);
Mesh.PhysicsAssetInstance.SetAllBodiesFixed(FALSE) ;
SetPawnRBChannels(TRUE);

if( TearOffMomentum != vect(0,0,0) )
{
ShotDir = normal(TearOffMomentum);
ApplyImpulse = ShotDir * DamageType.default.KDamageImpulse;

// If not moving downwards - give extra upward kick
if ( Velocity.Z > -10 )
{
ApplyImpulse += Vect(0,0,1)*DamageType.default.KDeathUpKick;
}
Mesh.AddImpulse(ApplyImpulse, TakeHitLocation, HitInfo.BoneName, true);
}
}

GotoState('Dying');

if (WorldInfo.NetMode != NM_DedicatedServer && UTDamageType != None && UTDamageType.default.bSeversHead && !bDeleteMe)
{
SpawnHeadGib(UTDamageType, HitLoc);

if ( !class'UTGame'.Static.UseLowGore(WorldInfo) )
{
HeadShotSocketName = GetFamilyInfo().default.HeadShotGoreSocketName;
SMS = Mesh.GetSocketByName( HeadShotSocketName );
if( SMS != none )
{
HeadshotNeckAttachment = new(self) class'StaticMeshComponent';
HeadshotNeckAttachment.SetActorCollision( FALSE, FALSE );
HeadshotNeckAttachment.SetBlockRigidBody( FALSE );

Mesh.AttachComponentToSocket( HeadshotNeckAttachment, HeadShotSocketName );
HeadshotNeckAttachment.SetStaticMesh( GetFamilyInfo().default.HeadShotNeckGoreAttachment );
HeadshotNeckAttachment.SetLightEnvironment( LightEnvironment );
}
}
}

}
}



defaultproperties
{

InventoryManagerClass = none //remove inventory

ViewPitchMin=-16000 //-18000
ViewPitchMax=18000

WalkingPct=+0.4
CrouchedPct=+0.4
BaseEyeHeight=32.0 //38
EyeHeight=32.0 //38
GroundSpeed=280.0 //440
AirSpeed=280.0 //440
DodgeSpeed=280.0 //600
DodgeSpeedZ=295.0
AccelRate=600.0 //2048
JumpZ=360.0 //322
CrouchHeight=22.0 //29
CrouchRadius=15.0 //21
WalkableFloorZ=0.7 //0.78

RotationRate=(Pitch=20000,Yaw=20000,Roll=20000)
MaxLeanRoll=2048
AirControl=+0.35
DefaultAirControl=+0.35
bCanCrouch=true
bCanClimbLadders=True
bCanPickupInventory=false //true
bCanDoubleJump=false //true

MaxMultiJump=0 //1 // remove multijump
bCanWalkOffLedges = true //allow to fall even if walking crouched

TransInEffects(0)= none //remove spwan effect TEST
TransInEffects(1)= none

MaxStepHeight=32.0 //26
MaxJumpHeight=49.0 //49

MaxFallSpeed=+820.0 //1250

//Push RigidBody
bPushesRigidBodies=true //false

//Remove mesh TEST
//Components.Remove(WPawnSkeletalMeshComponent)

//Custom Collision
Begin Object Name=CollisionCylinder
CollisionRadius=+0015.000000 //21
CollisionHeight=+0044.000000 //44
End Object
CylinderComponent=CollisionCylinder
}

MaVmAn
11-17-2010, 09:36 AM
I'm still stuck on this problem, any idea?

MaVmAn
01-06-2011, 09:30 AM
Bump again, with a summary:

When my player dies, the camera is spinning a while before going back to usual first person view, near to the ground.

I'd like to remove the spinning part.