How would I rotate weapon towards crosshair?

I’m currently working on a third person shooter (just for fun) and I try do everything on my own from searching and watching tutorials, but I’m stuck on this one. How would I go about rotating the weapon so that the projectile hits in the center of my screen?

In the picture, you see the black line is the trace going from the pistol (where the bullet would go) and the red line that I added in paint would be the direction I want the weapon to aim.
I do NOT want to just send the projectile that way without actually aiming the weapon in that direction. I want the bullet to go where the weapon is actually aiming.

I’ve been trying some things including rotating the top spine bone which both clavicles are connected to towards the center of the screen without success. I haven’t really figured out how to properly rotate it in that direction. I’ve tried CCDIK but my armature is not set up properly for it. I wish there was a way I could use IK but I would have to set up my armature differently in Blender, and I’m not sure how to do that. I also tried rotating my whole actor towards the center of the screen but it started spazzing out sending traces all over the place.

I think I would prefer if the whole upper body was rotated with the condition that the weapon was aiming at the center of the screen. How would I go about solving this?

UPDATE: I think I have solved it. Some minor tweaking needs to be done. I’ll post my solution here shortly in case someone is looking for a similar solution.

So I did manage to modify the yaw rotation of the top spine by fiddling around for a bit, so that it adds rotation to face where the trace from the center of the screen hits. Since the spine is only rotated forwards in the animation, the yaw is the same as the character’s.

It does align the aiming on the yaw axis now, but not the pitch. I’m thinking I could check the pitch rotation needed from the bone which shoots the aim trace in the weapon and apply it to the spine as well? EDIT: But that probably won’t work because the weapon bones rotates with the spine.

I’m getting myself all confused! This is most probably not the best way of solving this, but it’s the only way I can think of right now.

The white trace in the screenshot is the center of the screen.

This is how I accomplished this task. Hope this helps.


How did you do it?