Download

Run and Shooting Script

Hello guys.

As I said I’m using UTGame as a basis for my game, and a problem of UTGame is related to the character locomotion, there is no walk, just running. Even the running animation run_fwd_rif has the pawn running and aiming the gun.

However I changed the running animation for a sprint animation, similar to Resident Evil 6, where the character runs with the gun down, but the problem is that in this case when the player shoots while running it gets weird because the bullet comes out of the gun while the character is not aiming the gun in any direction (the gun in pointing down).

to solve this problem I used this code on the weapon class:


//function to fire gun and play animation/////////////////////////
simulated function FireAmmunition()
{

       //this will check if ammo reached zero to automatically reload weapon
       if ( AmmoCount <= 1 )
       {
       //this will call the simulated reload function
       Super.AutoReload();
       }

       //this will play the shooting animation only whenever the player is running, which is when it is needed to make the transition
       //between running and shooting

**      if(UTPawn(Owner).Velocity.x > 0 || UTPawn(Owner).Velocity.y > 0 || UTPawn(Owner).Velocity.z > 0)
       {

       //this will play the custom shoot animation only on the half top body
       UTPawn(Owner).TopHalfAnimSlot.SetActorAnimEndNotification(true);  
       UTPawn(Owner).TopHalfAnimSlot.PlayCustomAnim('idle_ready_rif', 1, 0.15, 0.15, true, false);

       }**

else
{
       UTPawn(Owner).TopHalfAnimSlot.StopCustomAnim(0.15);
}

super.FireAmmunition();
}
//function to fire gun and play animation/////////////////////////


So the statement** if(UTPawn(Owner).Velocity.x > 0 || UTPawn(Owner).Velocity.y > 0 || UTPawn(Owner).Velocity.z > 0)** will check if the pawn is running in any direction, if so, then it will play the idle_ready_rif animation on top body slot, which will make the character aim the gun while shooting.

It is working, however, sometimes it does not work, sometimes the character runs and shoots while the gun in pointing down, sometimes the **idle_ready_rif **does not play.

Is there a better way to do this?

Thanks!

You could always set a bool on the utpawn your using as a check. When he goes into sprint then set it to true, when he comes out of sprint set false.
then use that for a check and if it is true your sprinting return the function that fires, so it cant fire.

Thanks bro for the tip, yeah I will try do this way, maybe I need to set a condition for the sprinting. Something I realized, in Unreal Script, especially whenever triggering custom animations, is if I have more than one animation that I want to trigger on the same slot (i.e TopHalfAnimSlot), I need to set a kind of timer to let a delay, even if is 0.01s between them, otherwise some animations don’t play correctly.

However, I will again take a look at some tutorials on AnimationTrees, because I am using the default UT AnimTree, and I have some cool animations to use in a kind of enemy injured state (walking injured), and I think that making a custom AnimationTree from scratch will work better for me.

Thanks man, trully thanks!!!

:smiley:

Here is a function I wrote to get the time for any animation you play. This function is so you can get and use the time to delay it in a timer.

/use this to get animation play lengths, for all weapon animations/
function float GetWeaponAnimationPlaytime(name CurrentAnimation)
{
local int i;
local float PlayingTime;
local SkeletalMeshComponent NewMesh;

NewMesh = SkeletalMeshComponent(Mesh);
PlayingTime = 0.1;//beings it is local set it to something, so it will return a 0.1 time if nothing is found, so the settimer() will run at least.

for(i=0; i<NewMesh.AnimSets[0].Sequences.length; i++)
{

if(CurrentAnimation == NewMesh.AnimSets[0].Sequences*.SequenceName)
{
PlayingTime = NewMesh.AnimSets[0].Sequences*.SequenceLength;
break;
}

}

return PlayingTime;
}

Then you can use it like so.
ReloadTime = GetWeaponAnimationPlaytime(WeaponReloadAnim);

if(ReloadTime > 0)
{

if ( WeaponReloadAnim != ‘’ )
{ PlayWeaponAnimation( WeaponReloadAnim, ReloadTime );
}

if ( ArmsreloadAnim != ‘’ && ArmsAnimSet != none)
{
PlayArmAnimation( ArmsreloadAnim, ReloadTime );
}

if(!IsTimerActive(‘SetReload’))
{
SetTimer(ReloadTime, false, ‘SetReload’);
}

}

WOW man, thanks!!!

It will be very usefull for me, since I am still a noob in Unreal Script!!!

Cheers

:smiley: