I am trying to have my throwable items deal damage to other pawns and once it hits another pawn and the damage is dealt, the item will disappear, using Destroy().
Currently I am using the ApplyDamage function and leave the DamagedActor as OtherActor, which including the floor, walls, and such. Is there anyway that I can get all other pawn except the one I am controlling, so I can pass it into ApplyDamage()?
Is there anyway that I can get all other pawn except the one I am controlling, so I can pass it into ApplyDamage()?
If you want to apply damage to all the pawns except the one you’re controlling, you can get them all (e.g. via GetAllActorsOfClass(WithTag) like you’ve said above) and then loop through the array and call ApplyDamage on each of them.
If you meant, that you want to apply damage only when the OtherActor in your OnHit function is not a specific pawn, then I guess the way you’re checking it in your code above should work.
I have been writing C code for around about 35 years now, and I’ve never seen anyone use the comma operator in such a way (inside the ‘if’). Is that valid, and does it work like that?
… you want a thrown item to deal damage to all other pawns? are you sure that you’re explaining this correctly?
Hi, and yes, that is what I meant. Sorry for the confusion there.
I just want to deal damage to other pawns when throwing items at them, and I have been trying to figure out what I can do since ApplyDamage does not accept array.
I will try looping through the actors instead, thank you for the advice!
if (Cast<APawn*>(OtherActor) != nullptr && OtherActor != PlayerPawn)
also, you should probably set the owner of it when you spawn it, rather than when it hits something. Then you can just query the owner when it hits something to find out who threw it.
I can’t imagine there’s any good reason to tie the thrown item to GetFirstPlayerController’s pawn.