Determine the right AimOffset Yaw and Pitch so that the weapon's muzzle forward vector focus a target precisely

Hi,

i have a question for animators and math experts.

Here is a picture of a Test Blendspace2D:

What i wanna achieve is:

I have a target and i wanna aim this target. So i have to put in the right Yaw(X) and Pitch(Y) Input. But in the end the muzzle or the whole weapon’s forward vector shall precisely aiming the target, on point.

So i have to include a lot of variables like the weapon’s x offset, the heights of the individual aiming anims and so on.

I just wanna ask if anybody has deep experiences and already solved this. Any tips and tricks and smart ideas are also welcome.

Thanks in advance

raidfire.net

I’m not an expert, but this may help.

Normally, the Aimoffset is not intended for precise aiming. It helps you to create a visually acceptable aiming, but in the end many people just trace a line between the target and the weapon muzzle (it’s just a socket positioned just at the tip of your gun) and use this trace independently of how well your character, and weapon, is setted up towards the target.

This is why sometimes you see in games characters aiming slightly wrong but you hit the target anyway.

If you really want this kind of accuracy, this can be painful depending on the context. I had to do this for a game and it took me almost a month to make it perfect. It all depends on the type of character you have, the type of weapon, the camera positioning etc. In your case, as I can see by the picture, it would suffice to use the aimoffset to behave the character and you could use inverse kinematics to stay your hands on your weapon while you rotate its muzzle precisely towards the target.

Although it may seem easy talking this way, normally it is not, as it involves a lot of tests and re-checks and each case is different.

Great answer. I’d also like to mention that if you want really precise aiming, you can consider using an IK system. There’s several on the marketplace that can give you much more finer control of which direction the player’s weapon is aiming.

But as Basphdra says, 99% of games that I’ve seen simply do not care if the 3rd person player’s aim is slightly off. Most players don’t even notice it…

Here is what I plan on doing, not fully implemented yet. Should be good enough when combined with the muzzle to target trace. I gathered some data points and built two x/y line charts. X being the aim offset yaw and Y being the actual resulting rotation of the muzzle socket. For instance, when AO yaw is 0 I noticed that my socket on my muzzle was actually somewhere between 5-7 degrees to the right. It was not exactly linear but pretty close. Then if I trace from where my camera is out into the world (reticle) I get a hit result. I then trace from muzzle to hit result to get my desired rotation. I use the linear equation to solve for the AimOffset Yaw (solve for x given y). Then I use interpolate to get from current AO yaw to target AO yaw to smooth it. The interpolate just needs to stop when its ‘close enough’ the nearly equal node. That handles the animation side. Spawning a projectile should be given the exact look at rotation from muzzle to target to ensure it flies toward your reticle. For performance maybe you only do these traces if the mouse has moved beyond a certain threshold from previous trace hit. Also the traces are maybe done in one place and consumed by both the fire ability as well as the animation. Perhaps on a timer in the character, something like a few times per second. That will avoid line tracing on every tick which is probably excessive.