Announcement

Collapse
No announcement yet.

How would I rotate weapon towards crosshair?

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

    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.
    Last edited by nissekaka; 04-09-2019, 10:33 AM.

    #2
    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.
    Last edited by nissekaka; 04-03-2019, 06:25 AM.

    Comment


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

      Comment


        #4
        ohh you also need to look into setting up aim offset using animation system if you haven't already.

        Comment


          #5
          That's all very nice but I don't see how that's the solution to my problem. What you're doing is just tracing from the weapon to the center of your camera view (or screen)? I want my weapon to actually aim towards my crosshair and have the projectile that fires out of the weapon leave realistically, straight out of the barrel towards the mark.

          Comment


            #6
            Here is a GIF of how far I've come: https://s2.gifyu.com/images/aiming.gif

            The yellow trace is where the bullet will go, but I want it to match with the white trace through rotating it towards where I'm aiming, and not just send the projectile diagonally from the weapon. The solution I have come up with doesn't manage it as good as I would like.

            Comment


              #7
              Maybe start a line trace from the camera middle, and get the impact point vector. Then set world rotation or use "find look at" node to this impact vector?

              Comment


                #8
                Originally posted by Hermyth View Post
                Maybe start a line trace from the camera middle, and get the impact point vector. Then set world rotation or use "find look at" node to this impact vector?
                That is the direction I'm trying to go but I can't get it to work properly. I think an IK solution would be the best but I'm not sure how to set that up.

                Comment


                  #9
                  Okay, I'm still fighting this thing. I managed to get the weapon to aim correctly, however, I don't have any hand/torso IK setup.
                  https://prnt.sc/n9jshp I'm doing a trace from the character's eye towards the crosshair location but starting it a certain distance from the actual eye, this location represented by the debug sphere. I modify the pistol bone to this location, and then rotate the whole mesh towards the crosshair location. Not pretty!

                  Even worse is that if I try to use IK for the hands to correctly hold the pistol, since the pistol bone is a child to the right hand, the pistol also moves as shown in this picture: https://prnt.sc/n9jtw5

                  I just can't seem to find any information on this online. The only reference I have is this video: https://www.youtube.com/watch?v=QJZNIy7Dh6o




                  Comment


                    #10
                    SOLVED (sort of):

                    This is how I'm currently doing this. It is by no means perfect but yields the result I'm after. https://prnt.sc/n9pd71 - Here I'm getting the center of where my camera is looking.

                    https://prnt.sc/n9pe5q - I couldn't think of another way of getting a location between the character's eye and where I want him to aim than by doing this.

                    https://prnt.sc/n9peh3 - I set the location for the right hand bone. Since I want to have the pistol_IK bone positioned at this location, I move my hand bone relative to the pistol_IK bone.

                    https://prnt.sc/n9pemx - Here I get the rotation to the crosshair location for the weapon.

                    https://prnt.sc/n9pf07 - And finally the AnimBP where I move my hand_r, rotate the hand_r (adding pitch so the rotation moves with my AimOffset) and move my hand_l along with my hand_r and also look at where I'm aiming with the head.



                    When trying to solve this I'm mostly just doing it intuitively by trial and error without really knowing what I'm actually doing, so I don't understand everything perfectly. So I'm probably doing it way harder for myself than I need to. I'm sad to see there are no tutorials or no one talking about this out there, what I can find. I'm going to try to make it work better but this is what I have for now.



                    Result: https://giphy.com/gifs/ResIHq0UTlqwwVdaYA/html5


                    Comment

                    Working...
                    X