Hi guys. I made an Aim Down Sights system for the game I’m making. The problem is that the gun is rotated to the left to make hip fire accurate. When I right click to aim with the gun, the rotation of the gun stays the same. Is there any way I could rotate the gun to face the exact center of my screen once I right click? Here’s some examples:
Hip Fire
and aiming:
You can see when aiming the gun is slightly left by 5 degrees. I tried ‘Set relative location’ but the values don’t match up. Setting it to 90 degrees where it was before doesn’t put it back in the same spot. I’m a bit stumped here. Any help would be appreciated!
hi @StockSavage
is it attached to a socket? if so have you tried rotating the socket relative? just remember to put it back after aim.
@High500 Thanks for the reply. How exactly would I do that?
First off you need to setup the correct trace method for firing shots that hit center screen (crosshairs). Typically you don’t rotate the weapon for that.
Check my reply here for code.
Secondly you need to setup your weapon(s) to properly sit in hand. Here’s 2 vids on that including left hand IK code etc.
Positioning:
FABRIK left hand IK:
Thank you but I’ve already done most of that. I have a line trace system that can go from the gun muzzle to the center of the screen, and another more realistic one that shoots from the gun muzzle and goes straight, which is what I’m using now. I just want the more realistic trace to work while hip firing also. I’ve also got an IK system for the arms.
The trace I linked to always goes from muzzle to crosshairs regardless of camera position or weapon orientation.
If you really want to stick with the orientations then you have to create additional IK left hand offsets. The effector has to be updated per frame in the animgraph.
In the weapon class you’ll need to do relative rotation changes on the mesh. In hip stance it uses X rotation. In ADS stance it uses Y rotation. Simple struct or data table to hold the values.
Create two Events to transition to the different rotations.
In the character class when you go to hip call the weapon hip event. When you go to ADS call the weapon ads event.
You could also jus call these with anim notifies.
For flow control create an enum (None, Hip Stance, ADS Stance). Set the enum accordingly in the character class.
Many ways to do this, but the easiest and less bloated is what I previously posted.
Well my current problem is I can’t get the right relative rotation values. it’s 90 degrees when I’m ADSing but when I set it back to 90 it’s still too far left. What could be causing this?
I fixed it.
Could you explain how for others?
Yeah I just rotated my character mesh to the left and it lines up without having to rotate the gun. For some reason I had rotated him when I first made the bp and forgot.
Easily done, at least you are sorted!