Help with Stealth Kill Script

Hello guys

I am trying to polish my “Stealth Kill” script, which I used here:

It basically plays the kill and death animation synchronized on the player (kill anim) and on the enemy (death anim), then it kills the enemy.

On this video, this system did not work like I want and like it is mean to work.

On that chainsaw execution, this custom gun (UTWeap_Chainsaw) plays the kill animation on the player mesh as soon as the player shoots the weapon inside the simulated function FireAmmunition()

UTPawn(Owner).FullBodyAnimSlot.SetActorAnimEndNotification(true);
UTPawn(Owner).FullBodyAnimSlot.PlayCustomAnim(‘Chainsaw_Anim_Attack_Final’, 1.30);
PlaySound(SoundCue’A_VoicePack_GEARSofWAR_Marcus.****You_02_Cue’, false, true, true, vect(0,0,0), false);
super.FireAmmunition();

And the enemy pawn plays the death animation as soon as hit by the gun (event take damage)

But this is not correct, the right thing to do is to just play the animation whenever the player hits the enemy with the gun.

Also, I have many variations of synchronized animations (death and kill) that I want to use. I found an easy way to use it is by having many enemy pawn classes, each one with a unique pair of animations (death and kill), like enemy_death_kill_A, enemy_death_kill_B, but for this to work I need that the enemy pawn triggers the animation on the player pawn, which I DON’T KNOW how to do it.

I tried this, however i received the error message “Cast from Controller to UTPawn will always fail”.

Any help?

//all the animation will be played inside the TakeDamage Event
event TakeDamage(int Damage, Controller EventInstigator, vector HitLocation, vector Momentum, class<DamageType> DamageType, optional TraceHitInfo HitInfo, optional Actor DamageCauser)
{

//this variables will be used to play the camera animation on the player controller
local Playercontroller localplayer;

//this statement will check if the enemy was attacked by the knife weapon
//if yes, then it will play the knife Death Animation
if (DamageType == class’UTWeap_Knife’)
{

//this is the function to play the camera animation
//we placed this function here because it must only play the animation if the enemy is hit by the knife
ForEach LocalPlayerControllers(class’PlayerController’, localPlayer)
{
UTPlayerController(localplayer).PlayCameraAnim(‘MyCameraAnim’,false);
UTPlayerController(localplayer).ClientSpawnCameraLensEffect(class’knifeCameraBlood’);
}

//this statement will play the knife death animation on the enemy pawn
FullBodyAnimSlot.SetActorAnimEndNotification(true);
FullBodyAnimSlot.PlayCustomAnim(‘knife_kill_1_enemy’, 1, 0.25, 0.25);

//this statement will play the knife kill animation on the player pawn
//THIS IS NOT WORKING

**UTPawn(EventInstigator).FullBodyAnimSlot.SetActorAnimEndNotification(true);
UTPawn(EventInstigator).FullBodyAnimSlot.PlayCustomAnim(‘knife_kill_1_player’, 1, 0.25, 0.25); **

//this will freeze the enemy pawn
Super.DetachFromController();
Super.StopFiring();
GroundSpeed=0;

//this is a timer that will call for the function deathsequence and come back to normal
setTimer(2.0, false, ‘KillEnemy’);

}

}

I don’t know about the rest of the issue, but for that one error, the problem is that EventInstigator is a Controller. You’re trying to turn it into a UTPawn. That’s not going to work. You might be able to get the code to run if instead you cast UTPawn(EventInstigator.Pawn), but I don’t know if it’ll do what you want it to do.

WOW MAN YOU ARE A GENIOUS!!! IT WORKED!!! :D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D

I just need now to adjust the animations a bit to synchronize perfectly!!!

Thanks a lot dude, and by the way, your game is looking awesome. I always follow your updates. Good Work!

I have got 2 main types of animations, some animations are played whenever the player aproaches the enemy from behind, and other animations are player whenever the player aproaches the enemy from front.

How can I allow the pawn code to select the animations (front or behind)? How can the enemy pawn detect the player is behind him?

Any help?

You need to use a dot product. It’ll be something like this:



if(vector(Attacker.Rotation) dot vector(Target.Rotation) >= 0) // i.e., they're facing the same direction
{
    // Do back attack animation
}
else // i.e., they're facing each other
{
    // Do front attack animation
}


Edit: Also, thanks. I’m glad the code worked and I’m glad you’ve been following my game. :smiley:

Thanks bro. I trully love this Comunity. Even tough some people consider UE3 dead, but talented people like you proof that UDK/UE3 still rocks!!!

I will try right now this code!

:smiley:

I received this error when compiling scripts

Error, ‘vector’ conversion: Bad or missing expression


event TakeDamage(int Damage, Controller EventInstigator, vector HitLocation, vector Momentum, class<DamageType> DamageType, optional TraceHitInfo HitInfo, optional Actor DamageCauser)
{

    local int OldHealth;

    local Playercontroller localplayer;

    if (DamageType == class'UTDmgType_Knife')
    {

    ForEach LocalPlayerControllers(class'PlayerController', localPlayer)
    {

      UTPlayerController(localplayer).PlayCameraAnim(MyCameraAnim,,,,,false);
      UTPlayerController(localplayer).ClientSpawnCameraLensEffect(class'ChainsawCameraBlood');
      UTPlayerController(localplayer).IgnoreLookInput(true);
      UTPlayerController(localplayer).IgnoreMoveInput(true);  
      UTPlayerController(localplayer).ConsoleCommand("God");
      SetTimer(3.04,false,nameof(ReturnNormal));

    }

       if(vector(Attacker.Rotation) dot vector(Target.Rotation) >= 0) // i.e., they're facing the same direction
       {

       // Do back attack animation

       //this statement will play the knife death animation on the enemy pawn
       FullBodyAnimSlot.SetActorAnimEndNotification(true);
       FullBodyAnimSlot.PlayCustomAnim('knife_kill_1_back_enemy', 1.0, 0.25, 0.25, true, false);

       //this statement will play the knife death animation on the player
       UTPawn(EventInstigator.Pawn).FullBodyAnimSlot.SetActorAnimEndNotification(true);
       UTPawn(EventInstigator.Pawn).FullBodyAnimSlot.PlayCustomAnim('knife_kill_1_back_player', 1.0, 0.25, 0.25, false, false);

Yeah, I gave you pseudocode. You need to decide who Attacker and Target actually are. So I guess Attacker might be EventInstigator.Pawn and Target would be self?

Yes exactly. I the player am the attacker UTPawn(EventInstigator.Pawn) and target is the Enemy Pawn (self, in which the code is running). Sorry dude, but I am still a beginner in Unreal Script, so I thank you too much for taking your time and helping me :D. So how can I define the attacker and target?

I tried if(vector(UTPawn(EventInstigator.Pawn).Rotation) dot vector(Super.Rotation) >= 0) but the compiling error was: Unknow function Rotation in Class UTGame.UTPawn

Do Rotation instead of Super.Rotation. You access Super when you want to run the parent class’ version of a function. This Pawn’s rotation is exactly the same as if it were its parent class.

WOW MAN, YOU ARE A GENIOUS AGAIN!!! IT WORKED. I DON`T KNOW HOW TO THANK YOU MAN!!! You trully rock!!! Yeah, now the code works, perfecty, it detects whenever the player aproaches the enemy from behind and from front. Thanks!!!:D:D:D:D:D:D:D:D:D:D:D:D:D:D

Hello guys,

It`s me here again, sorry to be annoying however I find that the best way to learn unreal scripting is by seeking help from the comunity here.

After Nathaniel3W helping me with trigerring the kill animations on both player and enemy, I just want to add a special “spice” to my stealth kill script. I want to add a cool camera animation effect (like Gears of War Chainsaw and Turok 2008 Knife Kills).

I know there are 2 ways of having camera animations, one is by using a camera rig (Camera Rig - Cinematic Animations - Epic Games Forums) and other is by animating a camera in matinee then export to camera animation.

I am going with the second method, which for me is easier, and more intuitive.

I did create a new blank map, imported my hero skeletal mesh, my enemy skeletal mesh, created a new matinee sequence on which I load the kill and death animation on these characters, then I added a new camera actor on scene, tried to position the camera behind the player (3rd person view), I tried to match as close as possible my custom camera class, which is just the behindview with some offsets:

This is a part of my pawn code:

//override to make player mesh visible by default
simulated event BecomeViewTarget( PlayerController PC )
{
local UTPlayerController UTPC;

Super.BecomeViewTarget(PC);

if (LocalPlayer(PC.Player) != None)
{
UTPC = UTPlayerController(PC);
if (UTPC != None)
{
//set player controller to behind view and make mesh visible
//since we are not using the Pawn.CalcCamera() function so camera animations (chainsaw execution, i.e) will work normally
UTPC.SetBehindView(true);
SetMeshVisibility(UTPC.bBehindView);
}
}
}

defaultproperties
{
CamOffset = (X=6, Y=15, Z=-42);

So then I just created a camera animation on this matineer sequence, then exported the camera animation and called it on my code whenever the player performs the knife kill on the enemy:

   if(vector(UTPawn(EventInstigator.Pawn).Rotation) dot vector(Rotation) &gt;= 0) // i.e., they're facing the same direction
   {

   // Do back attack animation///////////////////////////////////////////////////////////////////////////////////////////////////

   ForEach LocalPlayerControllers(class'PlayerController', localPlayer)
   {

   //this is the function to play the camera animation
   UTPlayerController(localplayer).PlayCameraAnim(CameraAnim'Cameras.KnifeKillCamera',,,,,false);

It works, very good, exactly as the matinee sequence, however, there is only a small (or maybe BIG) problem. Is that the camera animation is added over the current camera position in game, that means if if dont move the mouse (look) and just press the button to trigger the knife kill, the camera animations plays exactly like it does on the matinee sequence. However, if whenever approaching the enemy to perform the knife kill, the player in example moves the mouse (look) to the sky in example, the animation goes off the scene which I planed, I mean, the camera animation (in my case is a simple rotation and close) will play aditively to the current camera position, so in case instead of the camera rotate over the characters, it will just look at the sky and rotate arround an empty space.

How can I fix this? Is possible, in example, whenever the player trigger the knife kill sequence, to fix the camera to a specific position (in the case to match with my matinee’s camera initial position).

During the knife kill sequence I already added many commands to ignore any player input and movement untill the end of the animation:

   UTPlayerController(localplayer).IgnoreLookInput(true);
   UTPlayerController(localplayer).IgnoreMoveInput(true);  
   UTPlayerController(localplayer).ConsoleCommand("God");
   UTPlayerController(localplayer).SetCinematicMode (true, false, false, true, false, true);

My problem is to match my game’s camera initial position to the matinee’s camera initial position to have the camera animation effect working perfectly.

Any help?

Thanks :smiley:

What if when you start the kill animation, you set PlayerController.PlayerCamera.ViewTarget.POV.Rotation to be whatever the matinee’s starting rotation is?

Yeah bro, this is what I wanted. I`ll try to implement this code. So I just need to get the rotation value from matinee’s camera by looking at the editor right (x,y,z rotation)

Like this?

PlayerController.PlayerCamera.ViewTarget.POV.Rotation.Yaw = x value (the matinee camera value);
PlayerController.PlayerCamera.ViewTarget.POV.Rotation.Pitch = y value (the matinee camera value);
PlayerController.PlayerCamera.ViewTarget.POV.Rotation.Roll = z value (the matinee camera value);

?

Cheers bro

Hello dude, I have added this code to my pawn’s knife kill script (because it is the enemy who triggers the knife kill sequence):

   UTPlayerController(localplayer).PlayerCamera.ViewTarget.POV.Rotation.Yaw = 90;
   UTPlayerController(localplayer).PlayerCamera.ViewTarget.POV.Rotation.Pitch = 90;
   UTPlayerController(localplayer).PlayerCamera.ViewTarget.POV.Rotation.Roll = 90;

I tried many values for Yaw, Pitch and Roll, however even though the code compiled with no errors, nothing changed. The initial camera rotation for the knife kill sequence is the actual camera rotation (controlled by the player mouse).

Thanks!

Sorry man, I’m not sure where to go from there. I would suggest writing the current ViewTarget.POV.Rotation onto the HUD in event PostRender so that you can see exactly what the current rotation values are. Then see if you can write an UnrealScript exec function that overrides player input and sets the rotation manually. See if you can get that to set the rotation to what you need for playing the kill-cam matinee. And remember that rotations in UnrealScript are measured in Unreal rotational units. (Best explanation is at Beyond Unreal, but their site is down right now. Google cache is here.)

Thanks bro you already helped me too a LOT. I staid the entire sunday (yesterday) searching on google and I already found a better solution for having cinematic cameras in-game:

https://forums.epicgames.com/udk/udk…tic-animations

This tutorial is fantastic!!! This way I can have a free camera animation with any initial and final position / rotation.

I will try this and see what I can do.

**If I find any troubles or stuck at some point of this tutorial, I will ask your help, ok bro? **:cool:

Anyway, THANKS BRO A LOT :slight_smile: