x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to align weapons sight with center of camera (Ironsight)

The game is a first person shooter in both C++ and Blueprint. Right now I have an aiming animation that brings the weapon to the center and aligns its sight with the center of the camera but it's not perfectly centered and it needs adjustment on the animation.

What I heard to be a good approach is to make a socket or maybe two for weapon sight and then use IK for hands and align it with the camera, but I don't know the math I need to do in order to achieve this. although It's a pretty standard thing to do in a FPS game but i haven't found any tutorials on it. so here are my questions :

  • How many sockets the weapon needs for its sight in order to align it to the camera?

  • For hands, Should i use 2 Bone IK or FABRIK for this purpose?

  • Are the hands needed to be already animated or it doesn't matter because IK does the job?

I appreciate an overall explanation on the steps I need to do. If there is a better approach other than animating it, please explain, thanks!

Product Version: UE 4.20
Tags:
more ▼

asked Sep 11 '18 at 07:04 AM in C++ Programming

avatar image

THIECK
17 1 2 7

avatar image ZeroParadigm Sep 11 '18 at 11:07 PM

Hi @THIECK, usually I try my best to answer OP question rather than suggest n alternative, but I was fortunate enough at work to have animators support the reverse IK solution so I don't know the steps off top of my head.

However, as a workaround until somebody more knowledgeable than I can provide the actual steps. What I did on my home project was to create two sockets on the weapon, one at the blades, and another at the post (perpendicular to the z axis). The I parent my camera to a scene component at the eye socket, and when I go into iron sights, I move the camera into alignment with the two weapon sockets.

In my situation, I don't have any clipping problems and the user is tricked into thinking their head has moved, when in reality it is just the camera. Maybe this will help for the short term until you can get the reverse IK working.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

I can only comment on a very simple manual approach I've used before:

During the animation that transitions your weapon from hip to ADS you interpolate your arms/weapon component to a relative offset so that it ends up aligned with your crosshair.

For example, suppose when you ADS and your current animation ends up being a bit off to the right & below of your crosshair, you manually determine what the relative location of your component must be (-Y and +Z in Unreal I think) to align with the crosshair and you store that as a variable on the weapon. Then during the go to ADS animation you interpolate from (0,0,0) to this stored relative location (SetComponentRelativeLocation if I recall correctly). Naturally you also interpolate out when going back to hip firing.

The only requirements are really that your ADS animation (outside of Unreal) must ensure that the sights are horizontally aligned as adding relative rotations can be a headache. The raw position of the ADS should also at least be in the ballpark of where it should end up to make it look ok.

more ▼

answered Sep 13 '18 at 10:28 AM

avatar image

staticvoidlol
2.6k 95 41 111

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question