How to program a horse in unrealscript( UDK WIP) ( pawns and vehicles )
Overview
To program a horse in Unrealscript the first thing you should know it's that you can use the class pawn in order to make it, after all a vehicle it's a pawn the only difference it's the name.
This is the result pressing W and A you go backward and forward and with A and D you turn left or Right.
It's less code than you think to make the basic stuff but
Step 1. Horse(pawn)
Here's the horse class. Wich extends from pawn, which means that it inherits the pawn functionality walking state and such. Vehicle it's kind of advanced stuff I learned watching it's player controller states though.
What you would need to do it's starting another class which extends of pawn, this class will handle the pawn getting the seat of the horse. We extend from pawn because we want AI to be able to move the horse aswell no vehicle required! The same applies to unreal engine 4.
//-----------------------------------------------------------
//Description: Written by Ferran Tantinyà or tantiñà Bernades.
//-----------------------------------------------------------
class GOTAMP2Horse extends pawn;
var() const DynamicLightEnvironmentComponent LightEnvironment;
//Body//
var(APVisual) const SkeletalMeshComponent MainBodyMesh;
//For getting touch event, to know if we are close enough
var(UsageVar) const CylinderComponent CylinderOfUsage;
var GOTAMP2Pawn GOTAPawnRidingHorse;
var GOTAMP2PlayerController ControllerRiding;
var() const particleSystem BloodScape1ParticleSystem;
var byte LastMovement;
var int GOTAHealth;
var bool inRagdoll;
var() name FallFromDyingHorseAnimation;
event PostBeginPlay()
{
super.PostBeginPlay();
}
DefaultProperties
{
Begin Object class=DynamicLightEnvironmentComponent Name=MyLightEnvironment
bSynthesizeSHLight=true
bIsCharacterLightEnvironment=true
bUseBooleanEnvironmentShadowing=false
End Object
Components.Add(MyLightEnvironment)
LightEnvironment=MyLightEnvironment
///////// MAIN BODY ////////////////////////
Begin Object class=SkeletalMeshComponent Name=MainBodyMeshComponent
AnimTreeTemplate = AnimTree'MPGOTA2AnimTrees.AnselmusMPAnimTree'
//General Mesh Properties
bCacheAnimSequenceNodes=FALSE
AlwaysLoadOnClient=true
AlwaysLoadOnServer=true
bOwnerNoSee=false
CastShadow=true
BlockRigidBody=TRUE
bUpdateSkelWhenNotRendered=false
bIgnoreControllersWhenNotRendered=TRUE
bUpdateKinematicBonesFromAnimation=true
bCastDynamicShadow=true
RBChannel=RBCC_Untitled3
RBCollideWithChannels=(Untitled3=true)
LightEnvironment=MyLightEnvironment
bOverrideAttachmentOwnerVisibility=true
bAcceptsDynamicDecals=FALSE
bHasPhysicsAssetInstance=true
TickGroup=TG_PreAsyncWork
MinDistFactorForKinematicUpdate=0
bChartDistanceFactor=true
RBDominanceGroup=20
bUseOnePassLightingOnTranslucency=TRUE
bPerBoneMotionBlur=true
ScriptRigidBodyCollisionThreshold = 0.5;
Translation=(Z=-76.0)
End Object
Components.Add(MainBodyMeshComponent)
MainBodyMesh=MainBodyMeshComponent
mesh = MainBodyMeshComponent
AccelRate = 200;
GroundSpeed = 1000;
//This one it's for touching so you can enter the city
begin object class=CylinderComponent Name=CompCollisionCylinder
CollideActors = true;
//BlockActors = true; //We don't necessarily need it, but it would block anyways.
end object
Components.Add(CompCollisionCylinder)
CylinderOfUsage = CompCollisionCylinder
bCanBeBaseForPawns=true
GOTAHealth = 150;
FallFromDyingHorseAnimation = UnconsiousGetUpBackwards
}
Step 2. PlayerController state of driving horse
In the player controller class, we will add a state in which we have to enter when we ride the horse.
state PlayerHorseDriving extends PlayerWalking
{
function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
{
Pawn.Acceleration = NewAccel;
}
/* Set the throttle, steering etc. for the vehicle based on the input provided
function ProcessDrive(float InForward, float InStrafe, float InUp, bool InJump)
{
} */
function PlayerMove( float DeltaTime )
{
local vector X,Y,Z, NewAccel;
local eDoubleClickDir DoubleClickMove;
local rotator OldRotation, NewRotation;
local bool bSaveJump;
local float NewYaw;
if( Pawn == None )
{
GotoState('Dead');
}
else
{
GetAxes(Pawn.Rotation,X,Y,Z);
// Update acceleration.
//NewAccel = pawn.Acceleration;
NewAccel = PlayerInput.aForward*X;
NewAccel.Z = 0;
NewAccel = Pawn.AccelRate * Normal(NewAccel);
if( VSize( pawn.velocity ) > 200 )
{
NewAccel = NewAccel + (X * 100) ;
}
NewYaw = NewYaw + ( PlayerInput.aStrafe / 4 );
NewRotation = Pawn.rotation;
NewRotation.Yaw = NewRotation.Yaw + NewYaw;
Pawn.SetRotation(NewRotation);
if (IsLocalPlayerController())
{
AdjustPlayerWalkingMoveAccel(NewAccel);
}
DoubleClickMove = PlayerInput.CheckForDoubleClickMove( DeltaTime/WorldInfo.TimeDilation );
// Update rotation.
OldRotation = Rotation;
UpdateRotation( DeltaTime );
bDoubleJump = false;
if( bPressedJump && Pawn.CannotJumpNow() )
{
bSaveJump = true;
bPressedJump = false;
}
else
{
bSaveJump = false;
}
if( Role < ROLE_Authority ) // then save this move and replicate it
{
ReplicateMove(DeltaTime, NewAccel, DoubleClickMove, OldRotation - Rotation);
}
else
{
ProcessMove(DeltaTime, NewAccel, DoubleClickMove, OldRotation - Rotation);
}
bPressedJump = bSaveJump;
}
}
function UpdateRotation( float DeltaTime )
{
local Rotator DeltaRot, ViewRotation;
ViewRotation = Rotation;
// Calculate Delta to be applied on ViewRotation
DeltaRot.Yaw = PlayerInput.aTurn;
DeltaRot.Pitch = PlayerInput.aLookUp;
ProcessViewRotation( DeltaTime, ViewRotation, DeltaRot );
SetRotation(ViewRotation);
ViewShake( deltaTime );
}
}
Comments
Post a Comment