How do I make my bullet go to my crosshair?
So, I have a Crosshair in the direct middle of my screen. I have a weapon set up that when I fire, it will use the spawn actor class node to spawn in the bullet. The only problem is, that the bullet goes where ever my gun is facing because the bullet is coming out of the socket. How would I make my bullet go to my crosshair? Would I have to use a line trace? How would I use a line trace? Help is appreciated! Thanks!
asked Nov 08 '18 at 05:15 AM in Blueprint Scripting
While you can draw a trace you don't need to in this case. Within the event tick set a custom variable "mouse location" by using:
'get player controller' -> 'get hit result under cursor by channel' -> 'break hit result' -> 'set'
You can now use the custom variable location along with the location of where the projectile is spawning to help build a transform for the 'spawn actor' node:
'find look at rotation' -> 'make transform' -> 'spawn actor'
Plug the projectile spawn location and mouse location into "start" and "target" pins respectively on 'find look at rotation' node. Plug the projectile spawn location and the result from rotation node into "location" and "rotation" pins respectively on 'make transform' node. Should give you the correct transform.
answered Nov 08 '18 at 06:01 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here