I am working on a FPS shooter with full body rather than separate hands and body approach, however this might be irrelevant.
The question is how do I make animations for aiming your weapon down its sights? Do I need to make separate aiming animations for each weapon where you position the hands in such a way that when you look at it from the camera the aim is at center of the screen? or do I need to tweak it programmatically?
making animations for each weapon aiming is tedious as you have to correct the animation again and again to make sure the sights are properly aligned when you play it in the game.
I am sure there is some more intelligent way that I don’t know of , can somebody help me out?
Hi. Find Tesla Dev on youtube. Last 4 videos are from his livestream. There he is making a game from scratch. You can see how he is setting up aiming and other stuff there. I would suggest starting with the video thats 2hours long. Just skip the parts where he is setting up vehicle if you want.
If you use a special bone for your camera positioning then you can create a camera in your DCC package, attach it to this bone, set its FoV, then “look through” it and setup the character’s pose as you want. That way you can be sure that you will see the exact same image in game.
However if you don’t use a bone for camera positioning then it’s kinda wild guessing but still doable. You can create a fake “aim” object and set it like a hundred units away, aligning with your character’s center and aim constraint your gun to this object.
Lol! I’m so stupid! All I had to do was to make approximate aiming animation and then in the game logic gently change the camera to a camera component in the gun actor.
Technically you make the gun as a Actor and then add a camera component in it such that its view is through the gun sights as you want to aim. Then all you have to do is when you want your character to aim just use setViewTargetWithBlend function to smoothly move the camera to the camera in the gun actor ! BAM you are now looking down the sights accurately without giving too much effort over aiming in animation.
I just used math
Check out me old TFPDemo.
Source is available with it.
Basically, its : target view location = sight location - (sight direction * ((direction from current view location to sight location normal | sight direction) * direction from current view location to sight location length)).
All this does is figure out a location parallel to the current view location that lines up with where ever the sight location is.
i.e. It’ll shift up and right, but not forward.
Up to you how to blend between the two, but I use FMath::VInterpTo().
Well that’s a more nerdy answer , and I’m lazy so I used the simplest solution, because when you visually place the camera component its much easier to place things at correct position than hard coding math and the best part is your game does not needs to know where the sights are.