How to check if the actor I'm looking at has tag?
I'm building a third person shooter and I'm trying to make the character shoot at the enemy only when aiming at it. Up to now, when in aiming mode, the character's aim offset is used to point where the camera is pointing, and an IsAiming boolean is used to prevent the player from shooting if not aiming, so bullets don't get fired everywhere if the weapon is not pointing "downrange".
My next step is to make the player only fire at enemies (I"m trying an auto fire system for mobile controls testing). I would like to trace from the camera and check if the first hit object is an enemy. I'm currently using an "IsEnemy" boolean on BeginPlay to differentiate characters that are not controlled, but I'm open to suggestions. I know about how to get the tag of object under cursor, but can't seem to find a way of doing it properly with the camera. The end goal is to trace while the player is aiming (from the active camera, also have a sniper camera) and if the actor that I point to is an enemy, call the Fire function.
It would be great if the solution was actually a line trace, because I could set the limit to be a variable "weapon range".
I'm pretty sure the answer is under my nose!
asked Aug 13 '19 at 07:59 PM in Blueprint Scripting
If you would like to check the tag, simply run a line trace and upon success get hit actor and use node Actor Has Tag. If actor has the right tag - run your Fire function.
Let me know if you need help setting this up.
answered Aug 13 '19 at 08:27 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here