Download

Line trace syntax to apply damage to character in c++

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<ACharacter>(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

There is both a GetActor() and GetComponent() which will give you the actor and the component

I know how to get those components, I just don’t know what the syntax is for applying damage because it’s not listed in intelesense

[TABLE]

0
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:[c++](https://answers.unrealengine.com/questions/topics/single/322.html)[line trace](https://answers.unrealengine.com/questions/topics/single/29148.html)[character collision](https://answers.unrealengine.com/questions/topics/single/16784.html)[apply damage](https://answers.unrealengine.com/questions/topics/single/37216.html)[syntax](https://answers.unrealengine.com/questions/topics/single/49867.html)[retag](https://answers.unrealengine.com/questions/713033/syntax-for-line-trace-hitting-and-applying-damage.html#)

edit|delete| more ▼

		asked **6 days ago**

https://secure.gravatar.com/avatar/e720c0050f4e2140b0bc6f956d741ef6?d=identicon

dougemmedhen
1 ● 2 ● 1

https://secure.gravatar.com/avatar/51aaa19618513c9efc818a7392ea9564?d=identicon&r=PG&s=16Dune5 days ago

		Do you have the actual code you are using? 			
  1. ACharacter* Person = Cast<ACharacter>(hit.getactor());
  2. if (Person)
  3. {
  4. if (Person->ActorHasTag(TEXT(“RegularDude”)))
  5. {
  6. }
  7. }

reply

https://secure.gravatar.com/avatar/e720c0050f4e2140b0bc6f956d741ef6?d=identicon&r=PG&s=16
reply

https://secure.gravatar.com/avatar/31599f2c03b10b4db32cac26ff29e32e?d=identicon&r=PG&s=16

https://secure.gravatar.com/avatar/e720c0050f4e2140b0bc6f956d741ef6?d=identicon&r=PG&s=16

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

		void ABullet::Tick( float DeltaTime ) { Super::Tick( DeltaTime ); 			
  1. FHitResult hit;

  2. FVector StartTrace = this->GetActorLocation();

  3. FVector EndTrace = (Velocity * DeltaTime) + StartTrace;

  4. EndTrace.Z += this->GetActorRotation().Pitch;

  5. FCollisionQueryParams params;

  6. params.AddIgnoredActor(this);

  7. if (GetWorld()->LineTraceSingleByChannel(hit,StartTrace,EndTrace, ECC_Visibility,params))

  8. {

  9. if (hit.GetActor())

  10. {

  11. DrawDebugSolidBox(GetWorld(), hit.ImpactPoint, FVector(10.f), FColor::Blue, true);

  12. ADestructibleActor *Mesh = Cast<ADestructibleActor>(hit.GetActor());

  13. if (Mesh)

  14. {

  15. Mesh->GetDestructibleComponent()->ApplyRadiusDamage(10.f, hit.ImpactPoint, 32.f, 10.f, false);

  16. }

  17. ATheMeleeDude *person = Cast<ATheMeleeDude>(hit.GetActor());

  18. if (person)

  19. {

  20. person->health = person->DamageResistance - damage;

  21. if (GEngine)

  22. {

  23. GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, “Poop”);

  24. }

  25. }

  26. }

  27. Destroy();

  28. }

  29. else

  30. {

  31. bulletexpire += DeltaTime;

  32. DrawDebugLine(GetWorld(), StartTrace, EndTrace,FColor(0.f,-bulletexpire * 80.f,100.f),true);

  33. SetActorLocation(EndTrace);

  34. Velocity += FVector(0.f, 0.f, 200.f) * DeltaTime;

  35. }

  36. if (bulletexpire > 3)

  37. {

  38. Destroy();

  39. }

       }
    
       The if statement doesn't run for person, any reason why?

If the IF statement isn’t running, then what you hit wasn’t a “ATheMeleeDude” actor. Have you placed a breakpoint and stepped through the code to see what you are hitting?

When I put a break point in the code for the if statement, the program doesn’t break.

Then put the break point up higher, you’re going to have to debug things step by step and find out where you are going wrong.

Consider this question closed I got my line trace working