x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Syntax for line trace hitting and applying damage to characters

I'm at my wit's end, I have a weapon line trace that applies damage to destructible meshes, now I'm trying to figure out how to apply damage to characters. Here's what I got: ACharacter *person= Cast(hit.getactor()); If(person->Actorhastag (FName ("RegularDude") { }

That's it. What is the syntax for actually hitting the character/capsule component? Please help me. The sooner I get this taken care of the better

Product Version: UE 4.14
Tags:
more ▼

asked Oct 06 '17 at 02:49 AM in C++ Programming

avatar image

dougemmedhen
1 2 1

avatar image Dune Oct 06 '17 at 01:27 PM

Do you have the actual code you are using?

 ACharacter* Person = Cast<ACharacter>(hit.getactor()); 
 if (Person)
 {
 if (Person->ActorHasTag(TEXT("RegularDude")))
 {
 
 }
 }

avatar image dougemmedhen Oct 06 '17 at 04:18 PM

Yes, I have the code that checks if the line trace hits something that's not null. The problem is I don't know the syntax for applying damage to a character as intelesense doesn't have a take damage function like I did when I checked to see if I hit a destructible mesh.

avatar image TestyRabbit Oct 06 '17 at 09:07 PM

So all Actors have a TakeDamage() function. I'm not exactly sure what the problem is, you shouldn't have any issue calling Person->TakeDamage(.......) after you make sure "Person" represents who you wanted.

avatar image dougemmedhen Oct 11 '17 at 09:31 PM

Here is the entire bullet hit/fire function during it's tick:

void ABullet::Tick( float DeltaTime ) { Super::Tick( DeltaTime );

 FHitResult hit;

 FVector StartTrace = this->GetActorLocation();

 FVector EndTrace = (Velocity * DeltaTime) + StartTrace; 
 EndTrace.Z += this->GetActorRotation().Pitch;

 FCollisionQueryParams params;

 params.AddIgnoredActor(this);

 if (GetWorld()->LineTraceSingleByChannel(hit,StartTrace,EndTrace, ECC_Visibility,params))
 {
     if (hit.GetActor())
     {
         DrawDebugSolidBox(GetWorld(), hit.ImpactPoint, FVector(10.f), FColor::Blue, true);
         ADestructibleActor *Mesh = Cast<ADestructibleActor>(hit.GetActor());
         if (Mesh)
         {
             Mesh->GetDestructibleComponent()->ApplyRadiusDamage(10.f, hit.ImpactPoint, 32.f, 10.f, false);
         }
         ATheMeleeDude *person = Cast<ATheMeleeDude>(hit.GetActor());
         
         if (person)
         {
             person->health = person->DamageResistance - damage;
             if (GEngine)
             {
                 GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "Poop");
             }
             
         }
     }
     Destroy();
 }
 else
 {
     bulletexpire += DeltaTime;
     DrawDebugLine(GetWorld(), StartTrace, EndTrace,FColor(0.f,-bulletexpire * 80.f,100.f),true);
     SetActorLocation(EndTrace);
     Velocity += FVector(0.f, 0.f, 200.f) * DeltaTime;
 }

 if (bulletexpire > 3)
 {
     Destroy();
 }

}

When I cast to TheMeleeDude, the if statement doesn't run. Any reason why?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Mark this as resolved I got my trace hitting the character.

more ▼

answered Oct 13 '17 at 05:21 AM

avatar image

dougemmedhen
1 2 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question