How to check if the actor I'm looking at has tag?

Hi!

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!

Thanks everyone.

Hello Fred,

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.

Hi Don,

Yes this is exactly what I was looking for! I had’nt used that in a while and was struggling to get the right node.

Thank you very much!

You’re very welcome. Always happy to help. :slight_smile:

Just on a side note, you could also use Cast to or Get Class for the actor you hit with line trace and take action based on that. Of course it all depends on your needs and design.