Announcement

Collapse
No announcement yet.

Collision with Particle System (Laser Beam)

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

    Collision with Particle System (Laser Beam)

    Hey All!

    Im making a 3D top down shooter/survival game and im stuck on a minor issue.

    Ive created a laser beam using a particle system, Its a straight line with one single colour, and comes out of the gun.

    Seems to work fine and shows where the player will be shooting.

    Issue i have is that the laser beam doesnt seem to interract with anything in terms of collisions. For example, in the picture below, you can see that the beam itself travels through the dummy target. It does similar things with walls and other objects.

    Click image for larger version  Name:	Untitled.png Views:	0 Size:	173.6 KB ID:	1736839

    Is there a way to change the particle system so that it "stops" once it hits something?

    Many Thanks!
    Looking for Level Design work https://tsayed.artstation.com/

    #2
    I believe you need to to a line trace outside the particle system. if the ray trace has a "hit" then obviously you check to see if the distance is LESS than your beam length, if it is, then you reduce your beam length during that tick. You can do a line trace with blueprints or c++

    https://docs.unrealengine.com/en-US/...nel/index.html

    Comment


      #3
      Originally posted by ViperG View Post
      I believe you need to to a line trace outside the particle system. if the ray trace has a "hit" then obviously you check to see if the distance is LESS than your beam length, if it is, then you reduce your beam length during that tick. You can do a line trace with blueprints or c++

      https://docs.unrealengine.com/en-US/...nel/index.html
      Ive already got a line trace coming out of my weapons muzzle so the player can shoot in the direction that the character is facing.
      Had to do it that way because its top down.
      Would i be able to use the same line trace for the laser beam?
      Looking for Level Design work https://tsayed.artstation.com/

      Comment


        #4
        One way is like this:

        https://i.imgur.com/h2gvffD.png

        He sets a start and end point for his laser beam particle.

        Comment


          #5
          Originally posted by ViperG View Post
          One way is like this:

          https://i.imgur.com/h2gvffD.png

          He sets a start and end point for his laser beam particle.
          For some reason that still doesnt work - The collisions work but IF theres nothing to collide with then the laser beam snaps to the center of the world.
          Last edited by KingSpud; 03-26-2020, 08:29 AM.
          Looking for Level Design work https://tsayed.artstation.com/

          Comment


            #6
            Try using an if node in BP connected to collision, saying "If no collision or hit detection, then laser beam is x length". Why would there not be collision, though? Like when the beam goes through an open door and doesn't detect what's in the next room yet?

            Comment


              #7
              Originally posted by presto423 View Post
              Try using an if node in BP connected to collision, saying "If no collision or hit detection, then laser beam is x length". Why would there not be collision, though? Like when the beam goes through an open door and doesn't detect what's in the next room yet?
              Im basically just using it in place of a crosshair. i think it looks slightly nicer.
              so yh id have a max length on the laser and only shorten the length then that hits a collider..

              Little confused with your If Node method though.

              This is whats currently happening - laser snaps to world center when theres nothing to collide with. It should just be one straight beam regardless
              Laser is snapping to world center when theres nothing to collide with infront of it
              Last edited by KingSpud; 03-26-2020, 11:14 AM.
              Looking for Level Design work https://tsayed.artstation.com/

              Comment


                #8
                I don't understand why it would snap to world center, either. Perhaps it's in the camera's settings, or the material's coordinate space of the laser beam. There's also the particle system defaults that may be doing it. With the If node, it's based on comparing A to B variables. I was thinking in terms of basic logic, but forgot that the if node compares A to B and outputs based on the results (A > B, or A < B). Isn't there an if-then capability in Blueprints?

                Comment


                  #9
                  ok so center of the world is just FVector 0,0,0. the reason why its going there is if you look at the final node (set beam target point) it wants you to feed it in a (new target point) which is a FVector. If you dont provide one, its going to just use 0,0,0, which is the center of the world.

                  So what you want is the players forward vector * some distance instead. (or at least the weapon barrel forward vector)

                  So in the blueprint there already is a playerfoward vector * maxlength that is being used for the line trace. one is plugged into start and the other end on the line trace node.

                  See if you can link the end (from the add node ) into the set beam target point (new target point). I'm at work so not sure if it will let you dual link but that should work as a default value.

                  basically your goal should be this. if there is a hit, then use that hit location as the beam end point. if there is not a hit (default end point) should be the exact same as the traceline end.

                  the player forward vector will work as long as the gun is pointing the exact same as the player. you can use either one of course, player forward vector or gun forward vector doesnt matter. if the gun is a different height then its better to use the gun for start and end points.
                  Last edited by ViperG; 03-26-2020, 01:52 PM.

                  Comment


                    #10
                    Originally posted by ViperG View Post
                    ok so center of the world is just FVector 0,0,0. the reason why its going there is if you look at the final node (set beam target point) it wants you to feed it in a (new target point) which is a FVector. If you dont provide one, its going to just use 0,0,0, which is the center of the world.

                    So what you want is the players forward vector * some distance instead. (or at least the weapon barrel forward vector)

                    So in the blueprint there already is a playerfoward vector * maxlength that is being used for the line trace. one is plugged into start and the other end on the line trace node.

                    See if you can link the end (from the add node ) into the set beam target point (new target point). I'm at work so not sure if it will let you dual link but that should work as a default value.

                    basically your goal should be this. if there is a hit, then use that hit location as the beam end point. if there is not a hit (default end point) should be the exact same values as the traceline start and end, which ends up being start point of the gun barel and end point is player forward vector * somedistance.

                    the player forward vector will work as long as the gun is pointing the exact same as the player. you can use either one of course, player forward vector or gun forward vector doesnt matter. if the gun is a different height then its better to use the gun for start and end points.
                    Okay from your message this is what i came up with which seems to work, If there is a blocking it then itll use the Location from the hit result as the end point of the beam, If not then it will use the Forward Vector * the Laser Length as the end point.
                    Click image for larger version

Name:	Beam.png
Views:	32
Size:	158.6 KB
ID:	1737423
                    Looking for Level Design work https://tsayed.artstation.com/

                    Comment

                    Working...
                    X