UE2 - UT2kX MovementAnims[] question

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

EvilT-ModZ

Un-Gravitify
Aug 3, 2011
42
0
6
30
Russia
www.set-games.ru
Hello there!

I want make a first-person fake body, which connected to third-person body.
So, It should play same animations as 3rd body.
How can I detect which MovementAnims is using by 3rd body at the moment?

I have tried to make it via angle between Pawn.Location and Pawn.Acceleration, but it works terrible

Code:
	local float fPointAngle;

	fPointAngle = Acos(Normal(vector(Pawn.Rotation)) dot Normal(Pawn.Acceleration))*180/PI;

	if( fPointAngle > -45.0 && fPointAngle < 45.0 )
		Anim = Pawn.MovementAnims[0];
	else if( fPointAngle > -135.0 && fPointAngle < 135.0 )
		Anim = Pawn.MovementAnims[1];
	else if( fPointAngle > -135.0 && fPointAngle < -45.0 )
		Anim = Pawn.MovementAnims[3];
	else if( fPointAngle > 45.0 && fPointAngle < 135.0 )
		Anim = Pawn.MovementAnims[2];

Will be great, if it will be same as 3rd-body, I think the way with angle will look different
 

meowcat

take a chance
Jun 7, 2001
803
3
18
See this UScriptAnimPawn UnrealWiki page I made a few years back. You should be able to use this in your first person fake body actor.

I've also been kicking around this same idea for a while (did some experiments with drawing the current pawn's body while in first person view). If I come up with anything, I'll post it.
 

forrestmark9

New Member
Aug 6, 2009
56
0
0
If this hasn't already been solved, I achieved something like this by spawning a actor only visible in first person and adding this to the defaultproperties

Code:
bAnimByOwner=True

Here's the full code of my FPActor if you want

Code:
class FPActor extends KFPawnFootAdjuster;

var int BodyLoc, CrouchLoc;
var Controller PawnController;

simulated function InitAdjuster(string CurrentMesh)
{
	UpdateDefaultMesh(SkeletalMesh(DynamicLoadObject(CurrentMesh, class'SkeletalMesh', true)));

	PawnController.Pawn.SetBoneScale(1, 0.001, 'larm');
	PawnController.Pawn.SetBoneScale(2, 0.001, 'rarm');
	PawnController.Pawn.SetBoneScale(4, 0.001, 'head');
}

simulated function AdjustBones(bool Type)
{
	if( !Type )
	{
		PawnController.Pawn.SetBoneScale(1, 0.001, 'larm');
		PawnController.Pawn.SetBoneScale(2, 0.001, 'rarm');
		PawnController.Pawn.SetBoneScale(4, 0.001, 'head');
	}
	else
	{
		PawnController.Pawn.SetBoneScale(1, 1.0, 'larm');
		PawnController.Pawn.SetBoneScale(2, 1.0, 'rarm');
		PawnController.Pawn.SetBoneScale(4, 1.0, 'head');
	}
}

simulated function Tick(float DeltaTime)
{
	local Vector PawnRotation;

	Super.Tick(DeltaTime);

	if(AdjustingPawn.Controller == none)
		return;
		
	if(KFHumanPawn(PawnController.Pawn).Health <= 0)
		AdjustBones(True);

	PawnRotation = vector(AdjustingPawn.Rotation);
	PawnRotation.Z = 0.00;

	if( AdjustingPawn != none )
	{
		if( PlayerController(AdjustingPawn.Controller).bDuck == 1 )
		{
			PawnRotation = float(CrouchLoc) * Normal(PawnRotation);
			SetLocation(AdjustingPawn.Location + PawnRotation + vect(1.35,0,19.5));
		}
		if( PlayerController(AdjustingPawn.Controller).bDuck == 0 )
		{
			PawnRotation = float(BodyLoc) * Normal(PawnRotation);
			SetLocation(AdjustingPawn.Location + PawnRotation + vect(0.41,0,6.5));
		}
		SetRotation(AdjustingPawn.Rotation);
	}
	
	if(AdjustingPawn != none && AdjustingPawn.Controller != none && !PlayerController(AdjustingPawn.Controller).bBehindView)
		AdjustingPawn.SetTwistLook(0, 0);
}

auto state Setup
{
	function InitBoneZ(bool bMax)
	{
		local Coords C;

		C = GetBoneCoords(SpecType.default.FeetBones[0]);
		C.Origin.Z -= SpecType.default.FootZHeightMod;
		if(bMax)
		{
			AdjustingPawn.MaxZHeight = -C.Origin.Z;
		}
		else
		{
			AdjustingPawn.MinZHeight = -C.Origin.Z;
			AdjustingPawn.MaxZHeight -= C.Origin.Z;
		}
	}

	function InitBoneRots()
	{
		local Rotator R;

		switch(SpecType.default.TorseRotType)
		{
			case BRot_Yaw:
				R.Yaw = SpecType.default.MaxTorsoTurn;
				break;
			case BRot_Roll:
				R.Roll = SpecType.default.MaxTorsoTurn;
				break;
			default:
				R.Yaw = SpecType.default.MaxTorsoTurn;
				SetBoneRotation(SpecType.default.TorsoBones[0], R);
				R = rot(0, 0, 0);
				switch(SpecType.default.KneeRotType)
				{
					case BRot_Yaw:
						R.Yaw = SpecType.default.MaxKneeTurn;
						break;
					case BRot_Roll:
						R.Roll = SpecType.default.MaxKneeTurn;
						break;
					default:
						R.Yaw = SpecType.default.MaxKneeTurn;
						SetBoneRotation(SpecType.default.KneeBones[0], R);
				}
		}
	}
	
Begin:
	Sleep(0.01);
	TweenAnim(SpecType.default.IdleAnimationName, 0.00);
	Sleep(0.10);
	InitBoneZ(true);
	InitBoneRots();
	Sleep(0.10);
	InitBoneZ(false);
	AdjustingPawn.bHasFootAdjust = true;
	stop;		
}

defaultproperties
{
     BodyLoc=-21
     CrouchLoc=-23
     bOnlyOwnerSee=True
     Mesh=SkeletalMesh'KF_Soldier_Trip.British_Soldier1'
	 bClientAnim=True
	 bOnlyRelevantToOwner=True
     bAnimByOwner=True
     bAlwaysTick=True
}
 

forrestmark9

New Member
Aug 6, 2009
56
0
0
Very nice ForrestMarkX, thanks for posting your solution!

Here's the entire code if you want

HumanPawn
Code:
replication
{
	reliable if( Role == ROLE_Authority )
		SpawnFPLegs;
}

simulated function Tick(float DeltaTime)
{
	local PlayerController PC;
	local bool BoneReset,bBehindViewToggled;

	PC = PlayerController(Controller);

	if( bHasFootAdjust && (Level.TimeSeconds-LastRenderTime) < 1 )
	{
		if(Adjuster != none && Adjuster.Mesh != Mesh)
			Adjuster.UpdateDefaultMesh(Mesh);
	}

	if(PC != none && PC.Pawn != none && bHasFootAdjust)
	{
		if( (Level.TimeSeconds-LastRenderTime) < 1 )
		{
			if(!PC.bBehindView && bBehindViewToggled)
			{
				bBehindViewToggled = false;
				FPActor(Adjuster).AdjustBones(false);
				if(KFPawn(PC.Pawn).Adjuster != none)
					KFPawn(PC.Pawn).Adjuster.bHidden = false;
			}
			else if(PC.bBehindView && !bBehindViewToggled)
			{
				bBehindViewToggled = true;
				FPActor(Adjuster).AdjustBones(true);
				if(KFPawn(PC.Pawn).Adjuster != none)
					KFPawn(PC.Pawn).Adjuster.bHidden = true;
			}
		}
		if( (PC.Pawn.Controller.IsInState('PlayerFlying') || PC.Pawn.Physics == PHYS_Swimming) && !BoneReset )
		{
			BoneReset = true;
			FPActor(Adjuster).AdjustBones(true);
			if(KFPawn(PC.Pawn).Adjuster != none)
				KFPawn(PC.Pawn).Adjuster.bHidden = true;
		}
		else if( (PC.Pawn.Controller.IsInState('PlayerWalking') || PC.Pawn.Physics == PHYS_Walking) && !bBehindViewToggled )
		{
			BoneReset = false;
			FPActor(Adjuster).AdjustBones(false);
			if(KFPawn(PC.Pawn).Adjuster != none)
				KFPawn(PC.Pawn).Adjuster.bHidden = false;
		}
	}
	
	super.Tick(DeltaTime);
}

simulated function Setup(xUtil.PlayerRecord rec, optional bool bLoadNow)
{
	Super.Setup(Rec, bLoadNow);

	bHasFootAdjust = False;
	FeetAdjSpec = Class<SPECIES_KFMaleHuman>(rec.Species);
	SpawnFPLegs(FeetAdjSpec, rec.MeshName);
}

simulated function SpawnFPLegs(class<SPECIES_KFMaleHuman> SpecType, string CurrentMesh)
{
	if(Bot(Controller) != None)
		return;
	if(Adjuster != none)
		Adjuster.Destroy();
	
	Adjuster = Controller.Spawn(class'FPActor', self,, Location, Rotation);
	Adjuster.AdjustingPawn = self;
	Adjuster.SpecType = SpecType;
	FPActor(Adjuster).PawnController = Controller;
	FPActor(Adjuster).InitAdjuster(CurrentMesh);
}

PlayerController
Code:
function ClientSetBehindView(bool B)
{
	super(PlayerController).ClientSetBehindView(B);
	
	if(SRHumanPawn(Pawn) != none)
	{
		if(B)
		{
			if(KFPawn(Pawn).Adjuster != none)
			{
				FPActor(KFPawn(Pawn).Adjuster).AdjustBones(true);
				KFPawn(Pawn).Adjuster.bHidden = true;
			}
		}
		else
		{
			if(KFPawn(Pawn).Adjuster != none)
			{
				FPActor(KFPawn(Pawn).Adjuster).AdjustBones(false);
				KFPawn(Pawn).Adjuster.bHidden = false;
			}
		}
	}
}

The only issue with this code is that when the pawn dies and goes into ragdoll his arms and head stay the same size for the FPActor so to the client he appears to be headless and armless but to others appears normal.

Some elements used here are found within the class KFPawn.uc
 
Last edited by a moderator: