currently I´m learning in UE4 while trying to script a little 3rd Person Shooter in Blueprints. So now I´m stucking at the aiming. Of cause I tried some other systems, like moving the projectile start point, but I don´t like this very much.
Well, I want that my weapons spots exactly one point in the world (I did this with an LineTrace starting at the “Get Camera World Location” output; see the pictures). If this LineTrace hits something, I want to set the Pitch- and Yaw-Offset from the AimOffset so, that the weapon spots to the Hit point from the LineTrace.
You can see 3 different colors and shapes:
The red circle shows the hit result from the Weapon LineTrace, the red line is that you can see the LineTrace better.
The green …well, it´s not a circle… shape shows the way that the weapon LineTrace moves (of cause, it´s not exactly!)
The yellow circle shows my Crosshair and the LineTrace from the Camera. Both are exactly in the middle of the screen
Ok, I want that the Weapon LineTrace(WLT) (the projectile follows this LineTrace) is exactly at the point where the Camera LineTrace(CLT) is. (Yeah, I can do it with setting the end-location of the WLT as the same as the Impact Point from the CLT, but I want to move the Weapon to get a realistic weapon aiming).
I thought that I have to get the rotation between these two LineTraces and set the Y and Z value of this rotator to the Pitch and Yaw from the AimOffset, but I don´t know how to do this.
Do a line trace originating from the pivot point of the gun (likely the wrist socket of the hand holding the gun) towards the point at the end of your crosshair trace (CLT)
Add a vector offset so that the trace from your gun alligns with the barrel.
Use trigonometry to compute the delta angle you need to get the “neutral gun position” (WLT) to the “crosshair corrected position”.
Apply the offset via your blend spaces.
Update us with your results! I actually need to do this exact thing for my own project amd it’d be great to see if my solution works for someone else.
I also wanted to do this, until i done multiplayer.
It is possible to synchronize this to every client?
All characters have some idle animation, synchronizing this on all clients may be impossible (for eg different framerate and something somewhere framerate dependent).
Also that blendspace is what i had in mind, so i assume i would have almost your setup.
So, I did a LineTrace from the Grip of my weapon to the Impact Point from the Camera LineTrace. Well… I do not understand 2. and 3. How do I get the vector offset? And how do I align the barrel to the trace?
You see… I´m really a noob in vectors, rotators and so on
All you need to do is replicate the value that dictates the positions in the blend-space right? So you create variables that the char has, they get set, and you read them from the anim bp and profit ?
Yeah that may work. Replicate Yaw and Pitch vars from blendspace, then calculate that correction offset on clients.
Also i think that it does not matter if projectile will go 2 degrees off from where gun is aiming, so instead calculating that offset just shoot projectile from muzzle socket right to target point. That direction difference will be invisible on screen.
But on other hand some animation induced bullet spread may look better than later randomizing impact location.
Of cause not, but what’s when you stand directly in front of an object? Your crosshair is… let’s say 2m over the ground. The weapon you’re holding is 1m over the ground. So the projectile flies (or flyes? I really don’t know) for example 20cm forwards and 1m upwards.
That’s actually the reason why I’m trying to geht this system to work.
Would be great if someone can help me | explain me how I can make the resolution from post #2
#2 assumes the barrel of the gun to be above the characters wrist. To correctly do trace, we just add the appropriate offset so the line traces off-bore.
#3involves mathematically solving the difference between the “neutral angle” (WLT in your example), and the line trace we did from #1.
This should have your character point the gun directly where the cross-hair is pointing, and do so all animation based. The tricky part off which I’m not entirely sure of is if blendspace animations can work in the level of precision needed to get the system working.
If that isn’t the case, adding a hard-coded rotational correction to the gun (after blendspaces gets the gun pointed near-ish to the direction we are shooting at) should make up the difference.
I´m hard, hard sorry, but I still don´t understand…
In #2 you mean, that I have to create a vector and manually adjust them, so that the LineTrace comming from my Weapon (WLT) + or - the vector created just in this step on the start and end point of the WLT is equal to the LineTrace I´ve created in the first Step?
And how do I get the difference from #3? (which note?)