Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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

    #2
    https://docs.unrealengine.com/latest...ne/FHitResult/

    There is both a GetActor() and GetComponent() which will give you the actor and the component
    https://www.casualdistractiongames.com

    Comment


      #3
      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

      Comment


        #4
        https://docs.unrealengine.com/latest...age/index.html
        Able Ability System - A high performance, robust ability system for UE4. Now Available!

        Comment


          #5
          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++line tracecharacter collisionapply damagesyntaxretag
          edit|delete| more ▼

          asked 6 days ago
          avatar image
          dougemmedhen
          1 ● 2 ● 1


          Dune 5 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


          reply





          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?

          Comment


            #6
            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?
            Able Ability System - A high performance, robust ability system for UE4. Now Available!

            Comment


              #7
              When I put a break point in the code for the if statement, the program doesn't break.
              Last edited by dougemmedhen; 10-12-2017, 11:32 AM.

              Comment


                #8
                Originally posted by dougemmedhen View Post
                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.
                Able Ability System - A high performance, robust ability system for UE4. Now Available!

                Comment


                  #9
                  Consider this question closed I got my line trace working

                  Comment

                  Working...
                  X