Hello, I thought it would be cool to show off some of the vaulting code I did in my game Zombies : http://forums.epicgames.com/showthread.php?t=772977
This is part of my source code and is subject to change. Remember, I am not a hardened programmer so if some of the things look pointless to a better programmer or there may be a better way then. There prolly is.
Video : http://www.youtube.com/watch?v=p3hGYA-Ev24
This is my first official tutorial so if you spot errors or mistakes please let me know.
I just hope someone appreciates this
So lets get started.
This requires the character to have a proper AnimTree and AnimSet(Containing FullBodyAnimSlot & TopHalfAnimSlot), if you hope to have the animations to work. Also prevent my script from giving errors.
Assuming you have a TrueFPS style pawn.
Make sure the pawn has a socket near the head called "Eyes"
Even if you dont have a true FPS style game, this will activate the camera in the world and make it look true FPS, if you have the proper 3rd person animations.
Enginebuild = March
Pawn.uc
In Your PlayerController.ucCode:class MainPawn extends UTPawn;
You will need to create a socket in you character pawn namedCode:var int ClimbHeight; var name VaultStartSocketName; var name VaultEndSocketName; var MainPawn P; var bool bVaulted; exec function Use() { local Actor TraceHit; local Vector StartLoc, EndLoc; local Vector HitNormal, HitLocation; if( Role < Role_Authority ) { PerformedUseAction(); } ServerUse(); // Trace from socket locations Pawn.Mesh.GetSocketWorldLocationAndRotation(VaultStartSocketName, StartLoc); Pawn.Mesh.GetSocketWorldLocationAndRotation(VaultEndSocketName, EndLoc); TraceHit = Trace(HitLocation, HitNormal, StartLoc, EndLoc,true,,, TRACEFLAG_Bullet | TRACEFLAG_PhysicsVolumes | TRACEFLAG_SkipMovers | TRACEFLAG_Blocking); DrawDebugLine(StartLoc, EndLoc, 255, 250, 100, true); if(TraceHit.IsA('VaultActor')) { GotoState('Vaulting'); } } ///*********** Vault STATE******************************************** //Contains stop functions and special case vaults. //handles animations and movement state Vaulting { function Check() { local VaultActor VA; local Actor TraceHit; local Vector StartLoc, EndLoc; local Vector HitNormal, HitLocation; foreach VisibleCollidingActors (class'VaultActor', VA,40,Pawn.Location) { // Trace from pawn sockets. Pawn.Mesh.GetSocketWorldLocationAndRotation(VaultStartSocketName, StartLoc); Pawn.Mesh.GetSocketWorldLocationAndRotation(VaultEndSocketName, EndLoc); TraceHit = Trace(HitLocation, HitNormal, StartLoc, EndLoc, true,,, TRACEFLAG_Bullet | TRACEFLAG_PhysicsVolumes | TRACEFLAG_SkipMovers | TRACEFLAG_Blocking); DrawDebugLine(StartLoc, EndLoc, 255, 250, 0, true); if(TraceHit.IsA('VaultActor')) { VA.Activate(); if(VA.Type == Tall) { bVaulted = true; Pawn.DoJump(bUpdating); Pawn.Velocity.Z = 700; P = MainPawn(Pawn); P.FullBodyAnimSlot.PlayCustomAnim('VaultTop', 1.0, 0.2, 0.2, FALSE, TRUE); SetTimer(0.4, false, 'Grounded'); } else if(VA.Type == Medium ) { bVaulted = true; Pawn.DoJump(bUpdating); Pawn.Velocity.Z = VA.Height; P = MainPawn(Pawn); P.FullBodyAnimSlot.PlayCustomAnim('VaultMediumSmall', 1.0, 0.2, 0.2, FALSE, TRUE); SetTimer(0.3, false, 'Grounded'); } else if(VA.Type == Small) { bVaulted = true; Pawn.DoJump(bUpdating); Pawn.Velocity.Z = VA.Height; P = MainPawn(Pawn); P.FullBodyAnimSlot.PlayCustomAnim('VaultSmall', 1.0, 0.2, 0.2, FALSE, TRUE); SetTimer(0.3, false, 'Grounded'); } } else { PushState('PlayerWalking'); } } } function Grounded() { local VaultActor VA; //Set forward 'push' velocity depending on the direction of the wall. determined by level designer. foreach VisibleCollidingActors (class'VaultActor', VA, 90, Pawn.Location) { if(VA.Direction == Left) { Pawn.Velocity.Y = VA.PushDistance; } else if(VA.Direction == Right) { Pawn.Velocity.Y = - VA.PushDistance; } else if(VA.Direction == Forward) { Pawn.Velocity.X = VA.PushDistance; } else if(VA.Direction == Back) { Pawn.Velocity.X = - VA.PushDistance; } PushState('PlayerWalking'); } bVaulted = false; } Begin: Check(); } defaultproperties { ClimbHeight = 0 bVaulted = false VaultStartSocketName = VaultStart VaultEndSocketName = VaultEnd }
Start = VaultStart
End = VaultEnd
Animations :
VaultTop
VaultMediumSmall
VaultSmall
VaultActor.uc
VaultActorSmall.ucCode:class VaultActor extends Actor placeable; var() const editconst DynamicLightEnvironmentComponent LightEnvironment; var() int Height; var() int PushDistance; var() bool bAttachCamera; var() name CameraEvent; //Vault type var() enum EType { Tall, Medium, Small }Type; //Vault direction var() enum EDirection { Left, Right, Forward, Back }Direction; simulated function Activate() { if(bAttachCamera == true) { TriggerRemoteKismetEvent(CameraEvent); } // Activate Specified Remote event within the level. For Level Designers. } //Query all remote events in level. function TriggerRemoteKismetEvent( name EventName ) { local array<SequenceObject> AllSeqEvents; local Sequence GameSeq; local int i; GameSeq = WorldInfo.GetGameSequence(); if (GameSeq != None) { // find any Level Reset events that exist GameSeq.FindSeqObjectsByClass(class'SeqEvent_RemoteEvent', true, AllSeqEvents); // activate them for (i = 0; i < AllSeqEvents.Length; i++) { if(SeqEvent_RemoteEvent(AllSeqEvents[i]).EventName == EventName) SeqEvent_RemoteEvent(AllSeqEvents[i]).CheckActivate(WorldInfo, None); } } } defaultproperties { Begin Object Class=DynamicLightEnvironmentComponent Name=MyLightEnvironment bEnabled=TRUE End Object LightEnvironment=MyLightEnvironment Components.Add(MyLightEnvironment) Begin Object class=StaticMeshComponent Name=BaseMesh StaticMesh=StaticMesh'LT_Buildings2.SM.Mesh.S_LT_Buildings_SM_BunkerWallA_STR' LightEnvironment=MyLightEnvironment CollideActors=true End Object Components.Add(BaseMesh) Begin Object Class=SpriteComponent Name=Sprite Sprite=Texture2D'EditorResources.S_Actor' HiddenGame=True AlwaysLoadOnClient=False AlwaysLoadOnServer=False End Object Components.Add(Sprite) CollisionComponent=BaseMesh bCollideActors=true bBlockActors=true Height = 750 PushDistance = 100 }
Place the actors in the level :Code:class VaultActorSmall extends VaultActor placeable; //Vault direction var() enum SDirection { Left, Right, Forward, Back }DirectionSmall; defaultproperties { }
To have the camera activate in game create a kismet sequence like the image below. Make sure you added a camera actor anywhere in the level and add that object as the image below;
Make sure you set the Kismet event name to something, and that it corresponds with the name given in the RemoteEvent name field in Kismet :
These are the values that must be set in the VaultActor Properties : (Note these are what works for me)
You can set it to Left, Right, Front, Back, so that you can have the player vault in any direction you want.
Note : You can only vault the actor in the direction you set it. So if you set FRONT. You can only vault it properly when in front of the actor. If you are behind you will appear to vault backwards. I will have it so it doesn't matter. However, for now this is how I have it.
![]()











Reply With Quote




Bookmarks