When i do linetracesinglebychannel the debugline does not appear

well i decided to use gametracechannel1, the only thing that i dont understand is why bool bSucces is not working, i have searched why it could be the reason but i wasnt capable of found the solution

gametracechannel1 would be the custom collision channel you made, did you make one? Did you set up the responses you want for that channel?

yes gametracechannel1 is the custom channel i made and yes i setted the responses, also the booleean bsucces is not working because is returning false how i solve it?

Could you show all of that?

ASword::ASword()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;
   
   Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
	SetRootComponent(Root);

	Mesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Mesh"));
	
	Mesh -> SetupAttachment(Root);
}

// Called when the game starts or when spawned
void ASword::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void ASword::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

void ASword::Hitting()
{
	
UE_LOG(LogTemp, Warning, TEXT("Hittin"));
	FHitResult Hit;
	FVector SwordDirection;

	//GetWorld()
bool  bSuccess = SwordTraceLine(Hit, SwordDirection);
if(bSuccess)
{
	DrawDebugPoint(GetWorld(), Hit.Location, 20, FColor::Red, true);
	UE_LOG(LogTemp, Warning, TEXT("Linetrace"));
	AActor* HitActor = Hit.GetActor();

	if(HitActor != nullptr)
	{
		FPointDamageEvent DamageEvent( Damage, Hit, SwordDirection, nullptr);
		AController* OwnerController = GetOwnerController();
		HitActor-> TakeDamage( Damage,DamageEvent, OwnerController,  this);
		//health =health + 30;
	}
	

} 
if(bSuccess == false)
{
	UE_LOG(LogTemp, Warning, TEXT("Not working"));
}
}

bool ASword::SwordTraceLine(FHitResult &Hit, FVector &SwordDirection)
{
AController* OwnerController = GetOwnerController();

	if(OwnerController == nullptr)
	{
		UE_LOG(LogTemp, Warning, TEXT("NNullptr"));
        return(false);
	}
	

	FVector Location;
	FRotator Rotation;

	OwnerController-> GetPlayerViewPoint(Location,  Rotation);

	
	 SwordDirection = -Rotation.Vector();

	

FVector End = Location + Rotation.Vector() * MaxRange;

	

	
	FCollisionQueryParams Params;
	Params.AddIgnoredActor(this);
	Params.AddIgnoredActor(GetOwner());


	return GetWorld() -> LineTraceSingleByChannel(Hit,Location, End, ECollisionChannel::ECC_GameTraceChannel1, Params);
	
	
}

AController* ASword::GetOwnerController() const
{
	APawn* OwnerPawn = Cast<APawn>(GetOwner());

	if(OwnerPawn == nullptr)
	{
		UE_LOG(LogTemp, Warning, TEXT("Null owner"));
	return nullptr;
	}
	 

	return OwnerPawn -> GetController();
	
}

And in Unreal?

you mean a gameplay?

No I mean the custom channel that corresponds to GameChannel1 and the actor you want to hits response to that channel.


1 Like


That shows that is ignoring the Sword channel when you want it to block.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms