Announcement

Collapse
No announcement yet.

Auto-Aiming to Crosshair?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Auto-Aiming to Crosshair?

    Hey,

    currently I´m learning in UE4 while trying to script a little 3rd Person Shooter in Blueprints. So now I´m stucking at the aiming. Of cause I tried some other systems, like moving the projectile start point, but I don´t like this very much.
    Well, I want that my weapons spots exactly one point in the world (I did this with an LineTrace starting at the "Get Camera World Location" output; see the pictures). If this LineTrace hits something, I want to set the Pitch- and Yaw-Offset from the AimOffset so, that the weapon spots to the Hit point from the LineTrace.

    In pictures:

    Click image for larger version

Name:	WeaponLineTrace.PNG
Views:	1
Size:	161.7 KB
ID:	1174897
    The Weapon LineTrace. The In-Exec comes directly from the "Event Tick" from the weapon Actor.


    Click image for larger version

Name:	CameraLineTrace.PNG
Views:	1
Size:	138.7 KB
ID:	1174896
    This is the Camera LineTrace Blueprint. The In-Exec comes from the Weapon LineTrace


    Click image for larger version

Name:	AimOffset.PNG
Views:	1
Size:	497.7 KB
ID:	1174898
    The AimOffset I use (Tutorial from Unreal Docs)


    Click image for larger version

Name:	InGame_LineTraces.PNG
Views:	1
Size:	553.5 KB
ID:	1174899
    You can see 3 different colors and shapes:
    The red circle shows the hit result from the Weapon LineTrace, the red line is that you can see the LineTrace better.
    The green ...well, it´s not a circle... shape shows the way that the weapon LineTrace moves (of cause, it´s not exactly!)
    The yellow circle shows my Crosshair and the LineTrace from the Camera. Both are exactly in the middle of the screen


    Ok, I want that the Weapon LineTrace(WLT) (the projectile follows this LineTrace) is exactly at the point where the Camera LineTrace(CLT) is. (Yeah, I can do it with setting the end-location of the WLT as the same as the Impact Point from the CLT, but I want to move the Weapon to get a realistic weapon aiming).



    I thought that I have to get the rotation between these two LineTraces and set the Y and Z value of this rotator to the Pitch and Yaw from the AimOffset, but I don´t know how to do this.
    Thanks 4 your time.
    LimSHulK

    #2
    Off the top of my head:
    1. Do a line trace originating from the pivot point of the gun (likely the wrist socket of the hand holding the gun) towards the point at the end of your crosshair trace (CLT)
    2. Add a vector offset so that the trace from your gun alligns with the barrel.
    3. Use trigonometry to compute the delta angle you need to get the "neutral gun position" (WLT) to the "crosshair corrected position".
    4. Apply the offset via your blend spaces.

    Update us with your results! I actually need to do this exact thing for my own project amd it'd be great to see if my solution works for someone else.
    Last edited by 6ixpool; 02-24-2016, 12:46 PM.
    Need another dev on your UE4 project? Send me a shoutout and I'll lend a hand

    Comment


      #3
      I also wanted to do this, until i done multiplayer.

      It is possible to synchronize this to every client?
      All characters have some idle animation, synchronizing this on all clients may be impossible (for eg different framerate and something somewhere framerate dependent).

      Also that blendspace is what i had in mind, so i assume i would have almost your setup.

      Comment


        #4
        Originally posted by 6ixpool View Post
        Off the top of my head:
        1. Do a line trace originating from the pivot point of the gun (likely the wrist socket of the hand holding the gun) towards the point at the end of your crosshair trace (CLT)
        2. Add a vector offset so that the trace from your gun alligns with the barrel.
        3. Use trigonometry to compute the delta angle you need to get the "neutral gun position" (WLT) to the "crosshair corrected position".
        4. Apply the offset via your blend spaces.

        Update us with your results! I actually need to do this exact thing for my own project amd it'd be great to see if my solution works for someone else.
        First of all, thank you for your reply.

        So, I did a LineTrace from the Grip of my weapon to the Impact Point from the Camera LineTrace. Well... I do not understand 2. and 3. How do I get the vector offset? And how do I align the barrel to the trace?
        You see.. I´m really a noob in vectors, rotators and so on
        Thanks 4 your time.
        LimSHulK

        Comment


          #5
          All you need to do is replicate the value that dictates the positions in the blend-space right? So you create variables that the char has, they get set, and you read them from the anim bp and profit ?
          Youtube
          Machine Learning C++ Plugin
          Lindenmayer System C++ Plugin

          Comment


            #6
            Yeah that may work. Replicate Yaw and Pitch vars from blendspace, then calculate that correction offset on clients.

            Also i think that it does not matter if projectile will go 2 degrees off from where gun is aiming, so instead calculating that offset just shoot projectile from muzzle socket right to target point. That direction difference will be invisible on screen.

            But on other hand some animation induced bullet spread may look better than later randomizing impact location.
            Last edited by Nawrot; 02-24-2016, 01:48 PM.

            Comment


              #7
              Originally posted by Nawrot View Post
              Also i think that it does not matter if projectile will go 2 degrees off from where gun is aiming, so instead calculating that offset just shoot projectile from muzzle socket right to target point. That direction difference will be invisible on screen.
              Of cause not, but what's when you stand directly in front of an object? Your crosshair is... let's say 2m over the ground. The weapon you're holding is 1m over the ground. So the projectile flies (or flyes? I really don't know) for example 20cm forwards and 1m upwards.
              That's actually the reason why I'm trying to geht this system to work.

              Would be great if someone can help me | explain me how I can make the resolution from post #2
              Last edited by LimSHulK; 02-24-2016, 02:22 PM.
              Thanks 4 your time.
              LimSHulK

              Comment


                #8
                #2 assumes the barrel of the gun to be above the characters wrist. To correctly do trace, we just add the appropriate offset so the line traces off-bore.

                #3involves mathematically solving the difference between the "neutral angle" (WLT in your example), and the line trace we did from #1.

                This should have your character point the gun directly where the cross-hair is pointing, and do so all animation based. The tricky part off which I'm not entirely sure of is if blendspace animations can work in the level of precision needed to get the system working.

                If that isn't the case, adding a hard-coded rotational correction to the gun (after blendspaces gets the gun pointed near-ish to the direction we are shooting at) should make up the difference.
                Need another dev on your UE4 project? Send me a shoutout and I'll lend a hand

                Comment


                  #9
                  Originally posted by 6ixpool View Post
                  #2 assumes the barrel of the gun to be above the characters wrist. To correctly do trace, we just add the appropriate offset so the line traces off-bore.

                  #3involves mathematically solving the difference between the "neutral angle" (WLT in your example), and the line trace we did from #1.

                  This should have your character point the gun directly where the cross-hair is pointing, and do so all animation based. The tricky part off which I'm not entirely sure of is if blendspace animations can work in the level of precision needed to get the system working.

                  If that isn't the case, adding a hard-coded rotational correction to the gun (after blendspaces gets the gun pointed near-ish to the direction we are shooting at) should make up the difference.
                  I´m hard, hard sorry, but I still don´t understand...

                  In #2 you mean, that I have to create a vector and manually adjust them, so that the LineTrace comming from my Weapon (WLT) + or - the vector created just in this step on the start and end point of the WLT is equal to the LineTrace I´ve created in the first Step?

                  And how do I get the difference from #3? (which note?)
                  Thanks 4 your time.
                  LimSHulK

                  Comment


                    #10
                    Well... Some more help would be great
                    Thanks 4 your time.
                    LimSHulK

                    Comment


                      #11
                      Ill edit this post later with (poorly drawn) pictures to help you understand my meaning a bit better.

                      I just need to get on my desktop
                      Need another dev on your UE4 project? Send me a shoutout and I'll lend a hand

                      Comment


                        #12
                        Originally posted by 6ixpool View Post
                        Ill edit this post later with (poorly drawn) pictures to help you understand my meaning a bit better.

                        I just need to get on my desktop
                        This would be great, thank you
                        Thanks 4 your time.
                        LimSHulK

                        Comment

                        Working...
                        X