hello all. i have two weapon. i want to spawn projectile from my weapons. first i want to add socket.i will use ray to crosshair. and my bullets will go to that direction. thank your for helps
Hello.
I did not understand what you’re trying to do ? I don’t get your drawing, can you detail a bit more how you want to calculate the direction ?
If your crosshair is centered on the screen, line trace from camera and use the hit location (or Trace End if it misses) and find lookatrotation for spawning projectile class.
For the socket location there, I used a mesh (called WeaponM in teh bp) attached to char’s hand which has its own muzzle socket. IF you char mesh has the guns baked in, add the socket to the characters skeletal mesh and get socket location from that.
No need to do a trace for shooting a projectile from a muzzle location toward center screen.
Variables and MATH.
In the projectile class create a vector variable ProjectileSpeed
set it to Instance Editable and Exposed on spawn.
In the construction script take PMC and Set Velocity
Pass Aim Velocity
to the spawn actor of class node for your projectile.
That works well when the camera is mostly horizontal, but when using camera forward * some arbitrary float, weird things can happen when aiming high or low. Like if aiming at the top edge of a wall, the crosshairs could be on wall while cam forward*2000+loc could be over and behind the wall in Ohio somewhere. Linetrace from camera pretty much assures you’r hitting what’s in the center of the screen. And as an added bonus, one could use the hit actor result to fire off interfaces functions or something on target to warn them if need be. EG, with a slow projectile, or shooting at Neo from the Matrix one might want AI to consider trying to dodge.
I use it all the time. It’s 100% deadeye to whatever I’m aiming at. Works 100% with Aim Offset as well.