How do I make the crosshair turn red when it's pointing at an enemy?

Valor

New member
Hi there. I'm currently making a game with the third person controller, and I saw in the demo that when your weapon is facing a target, the crosshair turns red. There is also an auto aim system. How do I use these?
 
Hi there. I'm currently making a game with the third person controller, and I saw in the demo that when your weapon is facing a target, the crosshair turns red. There is also an auto aim system. How do I use these?

If you put your enemy on an enemy layer, when the crosshair of your player is over it, it will turn red. And the auto-aim goes on the camera. If you look at the demo or even copy some stuff you may need from that you should be able to work it out.
 
@MissBig is spot on. These links should also help:

 
If you put your enemy on an enemy layer, when the crosshair of your player is over it, it will turn red. And the auto-aim goes on the camera. If you look at the demo or even copy some stuff you may need from that you should be able to work it out.
Thank you so much!
 
@MissBig is spot on. These links should also help:


Okay. Thank you to @MissBig and @Justin!
 
How could I add an event or function to this so when it activates the use or fire1 input is triggered? This seems like the place I would add such auto-fire function. Assuming it's possible, is there a way I could then disable this when a game pad is connected?
 
Hi Stonshallow, in the future if you could create a new thread when you have a new question that would be helpful!

If you're asking whether there's an event callback, there isn't one for that specific case. You can take a look at CrosshairsMonitor.cs to see how it checks if the mouse is over an enemy (in its Update) - it's a pretty simple raycast (actually a spherecast but performs the same kind of purpose).
 
Thanks. Yes I was looking at that, that's why I posted here apologies.

Can I just add a function in the update and use condition assuming I can find out how a gamepad is detected? I can't see anywhere how to call the use item ability, is there an example of that in the character locomotion script or where does that happen?
 
Top