Announcement

Collapse
No announcement yet.

VR Rail Shooter

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

    [OCULUS] VR Rail Shooter

    Hi everyone,

    I'm working on a VR rail shooter for the Oculus Rift and have been able to pick up the gun using the touch controllers, but can't figure out how to make the line trace shoot from the gun instead of where the HDM is looking. I have the gun as a separate blueprint from the player blueprint, unless it would be better(or make more sense) to add the gun to the player's blueprint. I want to use line trace as the gun will essentially be a laser tag type system.

    Ultimately I'd like to spawn with the gun attached to the motion controller or be able to pick it up at the beginning; whichever is easier for getting the line trace to work.

    Still trying to wrap my head around blueprints so any and all advice is appreciated, thanks!

    #2
    Line Trace by Channel has a Start point and an End point. If you want to line trace to originate from the tip of the gun, the Start point has to be the tip of the gun. Right now you are getting the position of the Player Camera, which corresponds to the HMD location, as starting point and this is the reason why your Line Trace always originates from the "head". You need to use the gun position instead.

    To get the coordinates of the tip of the gun, you can use GetWorldLocation on the gun blueprint and then add an offset to it (vector + vector). Or, which is easier, you can add an arrow to the gun and get the arrow component coordinates as Starting point for the Line Trace.

    For the End of the line trace, you need to get the forward vector of the gun (GetForwardVector), multiply it by the distance of the line trace, then add the result to the Start point above. Note that if the gun is attached to a motion controller and is aligned with it, you can also use the forward vector of the motion controller component itself to calculate the end of the trace.

    I recommend you give it a try and post again here if you can't get it to work as expected.
    CTO | Head of VR Development - Visit us at http://humanxr.com
    My UE4 Tutorials (mostly VR): https://goo.gl/GUvDyV

    Comment


      #3
      Thanks for the help vr_marco! Unfortunately, I wasn't able to get it to work still. I tried at least three different options to try to get it to work.

      In the first option, I tried using the motion controllers(R Motion Controller specifically) that spawn with the pawn for the line trace, like you had suggested, but that didn't seem to work. The second option I used the gun blueprint(which is separate from the pawn blueprint) to try to generate the line trace. With this option I tried both the StaticMeshComponent(Gun) as well as the GunArrow, with no luck for either. With the third option I decided to try adding a gun to the BP_MotionController and tried both the gun and gun arrow as two separate options again with no luck of getting it to work.

      For each of these tests, I made sure to disable the inputs for the ones I wasn't testing to avoid any problems. So the pawn doesn't have a gun attached to it, and like I mentioned has a separate blueprint that I use to pick up the gun after the level starts. It sounds like I may either need to figure out a way for the BP_Gun and BP_CoasterCar_DemoPawn to communicate with each other OR figure out a way to add the gun to the pawn so the player starts off with the gun in their hand from beginning(which would be perfectly fine with me).

      Again, thanks in advance for any help!





      Comment


        #4
        I suspect your child BP are never getting the input from the Motion Controllers. Do they have the Auto Receive Input: Player 0 set?
        CTO | Head of VR Development - Visit us at http://humanxr.com
        My UE4 Tutorials (mostly VR): https://goo.gl/GUvDyV

        Comment


          #5
          I have the pawn receiving player 0 input, if that's what you mean.
          Last edited by MTaylor3d; 04-16-2018, 06:00 PM.

          Comment


            #6
            Also the Blueprint where you handle the Motion Controller trigger event and do the raycast from it needs to receive the player input. Use a Print String debug to check that this is indeed the case, otherwise the event will never fire and the rays cast will never happen.
            CTO | Head of VR Development - Visit us at http://humanxr.com
            My UE4 Tutorials (mostly VR): https://goo.gl/GUvDyV

            Comment


              #7
              I was able to get the line trace to cast from the right motion controller which seems like a passable fix, but I just need to figure out how to add a vector that will offset the line trace from the hand to a position a little closer to where the barrel of the gun is. Here's the blueprint I used in addition to making sure motion controller trigger blueprint is set to the right input.

              Comment


                #8
                An easy way to do this from your gun blueprint us make a scene component and line it up with the tip of the gun. Name it GunStart. Then make a 2nd scene component which is basically the same position as the start but move it forward to where you want the shot to end and name it GunEnd. Now just plug the world location of the two into your line trace. No calculation needed.

                Also make sure to attach it to the Motion Controller components.
                Checkout Project "TwinBlaster" my current game in progress.
                [FREE] - 2D ROPE! Find out more here!
                Forgive my username... It's an old game name and wrote it down as a habit.

                Comment


                  #9
                  Thanks SkeetonYu!! I have a problem getting the hits to register with the line trace that I haven't been able to figure out using a blueprint interface. The hits are showing up green, but not destroying the target. I have a blueprint interface(BPI_Target) with "Was Hit" that is referenced in the VR Pawn and the target itself. Once I get this working, I'll implement the scoring system and play animations when a target is hit instead of destroying it.
                  Attached Files
                  Last edited by MTaylor3d; 05-08-2018, 12:43 PM.

                  Comment


                    #10
                    MTaylor3d DestroyActor does not make the destructible mesh break, it removes it altogether from the level. In case you want to break the destructible mesh but not hit it with another physics object (like a bullet) you have to use the technique described here:

                    https://answers.unrealengine.com/que...e-explode.html

                    Basically you add a radial force to it, which makes it "explode". This is what you need to to inside the implementation of your WasHit interface event.
                    CTO | Head of VR Development - Visit us at http://humanxr.com
                    My UE4 Tutorials (mostly VR): https://goo.gl/GUvDyV

                    Comment


                      #11
                      vr_marco I actually just was using the destroy actor as a way to see if the blueprint was working correctly, which it wasn't as the actor didn't destroy when I hit it. I don't want to destroy the actor at all, and just want to have points added to the score when it's hit. I had followed this tutorial series, but didn't seem to have success getting it to work properly. I would imagine that I'd also use a similar setup using a blueprint interface to get an animation to play once the line trace hits it.
                       

                      Comment

                      Working...
                      X