Announcement

Collapse
No announcement yet.

Using Traces for Weapon Bullets

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

    #16
    Originally posted by Kris View Post
    It seemed like people were complicating a very simple act, but then I found out GetActorEyesViewPoint() isn't callable by the Blueprint scripting system.
    It returns all the info you want for a basic trace like this.
    No mess, no fuss.
    But again, for some reason, its not setup to be blueprint callable
    Weird it wouldnt be in blueprints... I would think firing is one of the most common things done in a game from unreal. Since a lot of games are shooters... yet I've been finding it very difficult to find examples on how to fire a weapon, make it hit something and make it do something when it hits them etc.
    Snap-In Systems: <<< CLICK
    | Inventory (Battle Royale) |Smart Select Box | Ready Game Modes | Handy Macros | Gun Weapon System |Simple Mesh Outliner |

    Comment


      #17
      thought id post an update.

      This worked initially... and loooked good.. unfortunately now that ive progressed... I'm trying to do head shots and targeting hits when shooting and this only hits about 80% of the time.... the rest it just doesnt hit the mesh.

      I tried from the initial line and it hits everytime so theres an issue for sure calling the second line off the first one.

      So im back trying to figure out how to hit the crosshair form the barrel...
      since now i can either hit the crosshair from the camera.. or start it from the barrel but it doesnt go to cross hair...

      figure this would be standard settings

      frustrating.



      If anyone knows if this isnt a bug.. let me know please.

      Click image for larger version

Name:	blueprint.png
Views:	1
Size:	199.1 KB
ID:	1072134
      Click image for larger version

Name:	line not connecting.png
Views:	1
Size:	242.7 KB
ID:	1072135
      Last edited by thankstipscom; 04-08-2015, 02:35 AM. Reason: add screenshots.
      Snap-In Systems: <<< CLICK
      | Inventory (Battle Royale) |Smart Select Box | Ready Game Modes | Handy Macros | Gun Weapon System |Simple Mesh Outliner |

      Comment


        #18
        I found the answer in another thread if anyone has this issue.
        Though I don't quite understand why it needs to be done.

        From the Hit Result of the first line trace.... drag out Impact normal and * it by a float of -1
        Then drag out Location from the same node and + it by a vector (the impact normal *-1 result)
        Then the result of that equation, add to the end point of the second trace.

        While I understand what impact normal is.. i really dont understand why reversing it and adding it to the place it should impact to begin with is necessary.

        *sigh*


        Thread source: https://forums.unrealengine.com/show...-its-behaviour
        Snap-In Systems: <<< CLICK
        | Inventory (Battle Royale) |Smart Select Box | Ready Game Modes | Handy Macros | Gun Weapon System |Simple Mesh Outliner |

        Comment


          #19
          Impact normal indicates which way is outward from the surface.

          Multiplying it by -1 and adding it to the location of the hit is saying "wherever this hit occurs, aim one unit more TOWARD the object". Essentially it prevents situations where glancing impacts won't work correctly by correcting everything just a touch; instead of aiming at an object, you always aim one unit further toward that object.

          Personally I've never found it necessary (I resolved such issues by making the collision sphere for my bullet actors slightly larger) but if you're wondering WHY it works, that's the reason. It helps to correct for traces which would otherwise just barely impact an object.

          Though for this situation, what I prefer is not to trace TO the trace location, but THROUGH it. Once I had the impact of the first trace, I would use a "Find Look At Rotation" starting at my socket and ending at the trace impact, take that rotation, Get the XVector, and multiply that vector by some very large constant like 40,000.... And add the result to my start vector to get the actual shot trace's end vector.

          The reason being, a bullet doesn't travel from barrel to target; it just travels in a straight line. The first trace discovers the straight line from barrel to what's-under-the-reticle; if that's 900 units away or 9,000, it doesn't matter. The bullet has an effective range of X units and that should be the trace.

          IMO.
          Last edited by RhythmScript; 04-08-2015, 04:01 PM.

          Comment


            #20
            Originally posted by RhythmScript View Post
            Impact normal indicates which way is outward from the surface.

            Multiplying it by -1 and adding it to the location of the hit is saying "wherever this hit occurs, aim one unit more TOWARD the object". Essentially it prevents situations where glancing impacts won't work correctly by correcting everything just a touch; instead of aiming at an object, you always aim one unit further toward that object.

            Personally I've never found it necessary (I resolved such issues by making the collision sphere for my bullet actors slightly larger) but if you're wondering WHY it works, that's the reason. It helps to correct for traces which would otherwise just barely impact an object.

            Though for this situation, what I prefer is not to trace TO the trace location, but THROUGH it. Once I had the impact of the first trace, I would use a "Find Look At Rotation" starting at my socket and ending at the trace impact, take that rotation, Get the XVector, and multiply that vector by some very large constant like 40,000.... And add the result to my start vector to get the actual shot trace's end vector.

            The reason being, a bullet doesn't travel from barrel to target; it just travels in a straight line. The first trace discovers the straight line from barrel to what's-under-the-reticle; if that's 900 units away or 9,000, it doesn't matter. The bullet has an effective range of X units and that should be the trace.

            IMO.

            What if you don't have any bullet actors? The end of the line trace is where the "hit" is... i don't spawn any projectiles in this case.
            Snap-In Systems: <<< CLICK
            | Inventory (Battle Royale) |Smart Select Box | Ready Game Modes | Handy Macros | Gun Weapon System |Simple Mesh Outliner |

            Comment


              #21
              Originally posted by thankstipscom View Post
              Does it use line traces?

              I initially set up a projectile system using the FPS projectile tutorial.... but it seems like its more resource intensive to spawn a bullet every time and launch it when its just going to be invisible anyway.
              plus the gravity/physics and speed weren't lining up right for me.. but I don't know if I was doing it all correct. Seemed like the line trace method was the most practical for the speed of a gunshot. Figured Id use the other method for something like a grenade or whatever where you actually want to see the item flying through the air and bouncing around.
              Sorry for the late response.

              Yes, it uses line traces and has some rather complex math thrown into it. So it's not really a hitscan weapon, which might be what you're looking for. But it takes muzzle velocity, mass of projectile, diameter of projectile and all that stuff into account and even features ricochets.

              I think it's a great system to further improve upon, but I do not know how efficient it is in terms of performance. There should be some videos on youtube if you're interested.

              Edit:

              Forgot I had this video, which was me just messing around with it very early.

              Last edited by Dealman; 04-09-2015, 01:13 AM.

              Comment


                #22
                Originally posted by Dealman View Post
                Sorry for the late response.

                Yes, it uses line traces and has some rather complex math thrown into it. So it's not really a hitscan weapon, which might be what you're looking for. But it takes muzzle velocity, mass of projectile, diameter of projectile and all that stuff into account and even features ricochets.

                I think it's a great system to further improve upon, but I do not know how efficient it is in terms of performance. There should be some videos on youtube if you're interested.

                Edit:

                Forgot I had this video, which was me just messing around with it very early.


                looks cool.. I think I've learned enough to recreate that on my own actually.... but obviously i donno the depth of it.
                The issue though is that its built for FPS... TPS is slighlty different.. because those line traces come from the camera not from the gun or character..... im guessing that the blueprint youre showing has them coming from the camera as well... just out front x amount of space as the start rather than coming from the socket of the gun specifically.

                when doing it that way in a TPS game... the trace goes to the centre of the map... but thats not always the crosshair position... at a great distance it will at some point be the cross hair position...but thats not helpful when aiming obviously. I might check it out none the less though.. does it have some bullet effects included?
                Snap-In Systems: <<< CLICK
                | Inventory (Battle Royale) |Smart Select Box | Ready Game Modes | Handy Macros | Gun Weapon System |Simple Mesh Outliner |

                Comment


                  #23
                  Originally posted by thankstipscom View Post
                  What if you don't have any bullet actors? The end of the line trace is where the "hit" is... i don't spawn any projectiles in this case.
                  True, but my point is, if you trace from socket-to-reticle, the bullet (as simulated by a trace) effectively stops RIGHT AT what you want it to hit... what you want is for it to go way THROUGH that point. What I'm saying is, figure out the vector which points forward FROM the socket TOWARD the reticle's target trace location, and scale that vector up to be whatever you want the bullet's range to be (60,000 units, say). That way, instead of the game tracing from socket to target, it traces from socket THROUGH the target, which is a much better guarantor that the hit will register. This is especially important if the target is moving when the shot is fired; if the trace is performed before the actors' locations update, then the trace will trace to where the actor WAS last frame, before the update registers... and possibly miss as a result.

                  Comment


                    #24
                    Hey RhythmScript,

                    Thanks for all your help so far. I think I know what you mean, I tried a few times breaking the vectors but I kept messing up the locations.. so i reverted back. If you can maybe give a real example based on my bp attachment.. that could help.

                    Also noticed a new problem. When i shoot the enemy, its quite precise... registers exact bone hit etc... but if i put the crosshair off to the right i can still hit the enemy... because clearly the gun muzzle line of sight goes through the enemy to the crosshair. Any suggestions on how to fix this?




                    Click image for larger version

Name:	bp.png
Views:	1
Size:	266.6 KB
ID:	1072234
                    Click image for larger version

Name:	editor.png
Views:	1
Size:	103.8 KB
ID:	1072235
                    Snap-In Systems: <<< CLICK
                    | Inventory (Battle Royale) |Smart Select Box | Ready Game Modes | Handy Macros | Gun Weapon System |Simple Mesh Outliner |

                    Comment


                      #25
                      400 attemps at getting this right and yours worked thanks man

                      Comment

                      Working...
                      X