# Line trace by channel = death

**URL:** <https://forums.unrealengine.com/t/line-trace-by-channel-death/355196>\
**Category:** AI\
**Tags:** ai-navigation, actor, linetrace, unreal-engine, UE4, Blueprint, question\
**Created:** [April 23, 2016, 3:56pm UTC](https://forums.unrealengine.com/t/line-trace-by-channel-death/355196 "2016-04-23T15:56:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Canti\_Prime](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Canti\_Prime](https://forums.unrealengine.com/u/Canti_Prime)\
**Post date:** [April 23, 2016, 3:56pm UTC](https://forums.unrealengine.com/t/line-trace-by-channel-death/355196/1 "2016-04-23T15:56:50Z")

</div>

hey i have a line trace by channel for the first person template gun and have got it to hit my ai however i need to have the ai die but i don’t know how. I have gotten the ai to blow up when inear to the character but i have no clue how to do this.

---

<div class="post-metadata">

**Author:** ![leopaivaleo](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/leopaivaleo/32/625923_2.png) [@leopaivaleo](https://forums.unrealengine.com/u/leopaivaleo)\
**Post date:** [February 17, 2023, 3:51am UTC](https://forums.unrealengine.com/t/line-trace-by-channel-death/355196/2 "2023-02-17T03:51:15Z")

</div>

Hi there, hope you’re doing well 🙂  
I don’t know if I got the problem 100%, you want to kill the AI actor when the line trace hits it? Are u making this in blueprints or c++?  
If I got the problem right, you can do it by having a bool variable like “bIsDead” in your AI class that will be checked on tick function. In your MainCharacter class you make the line trace and checks the actor that was hit. If it’s the AI actor, cast to the AI and then set the bool bIsDead to true.  
In blueprints will be something similar to this:  
BP\_AI

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/1/d/d1dc4b9cf0e1beb7f5d046ec4db488c61426c4ba.png)

BP\_Character

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/3/f/73fface8ebb11cb00e00b8260c4ad24850c647fa.png)

And in c++, would it be something like this:  
AAIActor.h

```auto
public:
	bool bIsDead;
        FORCEINLINE void SetIsDead(bool bDead) { bIsDead = bDead; };

```

AAIActor.cpp

```auto
void AAIActor::BeginPlay()
{
    Super::BeginPlay();
    bIsDead = false;
}
void AAIActor::Tick()
{
    if(bIsDead== true)
	{
		// Call the dead function that you created
	}
}

```

MainCharacter.h

```auto
        UPROPERTY(EditAnywhere, Category = "Collision")
	TEnumAsByte<ECollisionChannel> TraceChannelProperty = ECC_Pawn;

	UPROPERTY(EditAnywhere, Category = "PickUp")
	float TraceLenght = 200.f;

```

MainCharacter.cpp

```auto
       // This code will be inside the function that you want to make the line trace
	FHitResult Hit;
	FVector TraceStart = FirstPersonCameraComponent->GetComponentLocation();
	FVector TraceEnd = FirstPersonCameraComponent->GetComponentLocation() + FirstPersonCameraComponent->GetForwardVector() * TraceLenght;

	FCollisionQueryParams QueryParams;
	QueryParams.AddIgnoredActor(this);

	// LineTrace
	GetWorld()->LineTraceSingleByChannel(Hit, TraceStart, TraceEnd, TraceChannelProperty, QueryParams);

//checking if the hit actor is the AI
    if(Hit.GetActor()->IsA<AAIActor>())
    {
        AAIActor* HitActor = Hit.GetActor();
        HitActor->SetIsDead(true);
    }

```

if I get it wrong or you don’t understand somethin, please let me know!
