No announcement yet.

How would I rotate weapon towards crosshair?

  • 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.

    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.


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


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


          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.


            Here is a GIF of how far I've come:

            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.


              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?


                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.


                  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.
         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:

                  I just can't seem to find any information on this online. The only reference I have is this video:


                    SOLVED (sort of):

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

           - 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.

           - 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.

           - Here I get the rotation to the crosshair location for the weapon.

           - 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.