Announcement

Collapse
No announcement yet.

How to create a laser that bounces on the walls and hurts players?

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

    How to create a laser that bounces on the walls and hurts players?

    Hi, I'm currently prototyping a simple multiplayer game (or so I thought) where players are able to shoot lasers and the laser bounces around in the level.

    However I'm not sure on how I should create the laser, but right now I spawn sphere projectiles that I've set bounce to true on.

    What I have in mind:
    Click image for larger version

Name:	ev0DlIL.gif
Views:	1
Size:	14.4 KB
ID:	1168857

    Currently:
    Click image for larger version

Name:	2erl8Uh.gif
Views:	1
Size:	5.1 KB
ID:	1168858

    Is it possible to create what I'm trying to make? I could have a game with balls but lasers are much cooler.

    Entire project is available on GitHub: https://github.com/Saucy/ue4-laserz

    #2
    There are probably at least 3-4 ways you could do what you need. Just thinking off the top of my head here...

    Make your current ball invisible and increase the speed to the point it would seem instant to travel it's maximum distance. Then each time it collides store the vector of the collision point. Then when it has reached it's limit, spawn a spline using the vectors of each collision.
    Map Generator 1.0
    Map Generator 2.0
    Map Generator 3.0

    Comment


      #3
      An idea how to do this is all I need at this point. Now I know where to start, thanks!

      Comment


        #4
        Making fast moving objects in unreal has one big problem. When you get to 2000-3000 speeds they sometimes go trough walls. I tried this fast moving projectile thing for weapons, and it does not work well.

        Instead i used line trace. You can trace line in direction you are aiming. You get location and normal vector in hit spot.
        So you have direction of incoming lazer, normal at hit point, you need to calculate bouncing vector.
        Easiest way is to normalize incoming vector, negate it then rotate 180deg around normal vector. There are probably faster methods (you should google this), but that rotating is first that came to my mind.

        Co now you should have impact point and calculated outgoing vector. Shoot new lazor.

        This also works great with beam particles, you can spawn new beam particle for each line trace.

        Comment


          #5
          have a look at MirrorByVector in the FVector class

          Comment


            #6
            I found this simple line trace tutorial on the wiki: https://wiki.unrealengine.com/Simple...Trace_Ricochet

            But I can't get it to work, he's using First Person Template, I'm doing a platformer.

            Anyway here's how it looks:

            Click image for larger version

Name:	wrong_reflection.png
Views:	1
Size:	27.6 KB
ID:	1097573

            The blueprint:

            Click image for larger version

Name:	wrong_reflection_blueprint.png
Views:	1
Size:	228.0 KB
ID:	1097574

            I don't understand how I can make something simple as draw a line from my character, to the mouse cursor and continue drawing the line 5000 units further. It's impossible.

            Every time I find a tutorial or something it's completely different from what I'm doing.
            I've tried it once before a TopDown prototype where I wanted to draw (yet another) laser, Magicka style.

            I just don't understand.
            Last edited by Ardoc; 12-27-2015, 04:52 PM.

            Comment


              #7
              you need debug line or gameplay one
              for gameplay look for beam emitter

              you can specify the source, target and tangents if you want the line to have some fancy form

              Comment


                #8
                I have a debug line, but its angle is off

                Comment


                  #9
                  I see 2 line traces in your BP but there are actually 3 line traces shown in your image so it is a bit hard to narrow down without more information.

                  In your image of the game, there is a line trace that appears to be going from the character to the correct mouse location. What part of your script is generating that trace? You need to isolate to that part and make sure that part is being used for the reflection.
                  Ryan Brucks
                  Principal Technical Artist, Epic Games

                  Comment


                    #10
                    I use only line trace to show where I am aiming (dunno how to make a drawn dotted line from player to mouse cursor).

                    The other lines are where I attack.

                    When the player attacks the laser should continue until it hits something and then bounce until it has reached max # bounces.
                    That's why I need to the laser to continue past the mouse cursor, otherwise it stops at it.
                    Like shooting a projectile that bounces endlessly until it hits something and bounces until it has reached max # bounces.

                    Aiming only:
                    Click image for larger version

Name:	linetrace_aim.png
Views:	1
Size:	12.9 KB
ID:	1097964

                    When I press attack, the angle is way off:
                    Click image for larger version

Name:	linetrace_attack.png
Views:	1
Size:	10.8 KB
ID:	1097965

                    Here's the blueprint:
                    Click image for larger version

Name:	aim_attack_blueprint.png
Views:	1
Size:	350.9 KB
ID:	1097962
                    Last edited by Ardoc; 01-04-2016, 04:05 PM.

                    Comment


                      #11
                      *edit, previous suggestion was not correct*

                      Looks like your 1st line trace is trying to 'project' the line by multiplying by 5000, but that is an actual world space location you are tracing *to*. You do not need to multiply that by 5000 there.

                      Also you may need to convert the position into a vector before doing "Mirror vector by normal". That vector can just be Normalize(Start - End). Then you mirror that, and then multiply the result of the mirrored vector by 5000 (or whatever your max length it)
                      Last edited by RyanB; 01-04-2016, 04:13 PM.
                      Ryan Brucks
                      Principal Technical Artist, Epic Games

                      Comment


                        #12
                        I don't understand well what are you trying to achieve , here is my comprehension :
                        You want to fire a laser in a direction and it will bounce from wall to wall ?
                        It will bounce continuously until it hits a player or the laser has a certain lifetime?
                        Website [ LINK ]
                        Twitter [ LINK ]
                        Support ! [ LINK ]

                        Comment


                          #13
                          Originally posted by RyanB View Post
                          *edit, previous suggestion was not correct*

                          Looks like your 1st line trace is trying to 'project' the line by multiplying by 5000, but that is an actual world space location you are tracing *to*. You do not need to multiply that by 5000 there.

                          Also you may need to convert the position into a vector before doing "Mirror vector by normal". That vector can just be Normalize(Start - End). Then you mirror that, and then multiply the result of the mirrored vector by 5000 (or whatever your max length it)
                          The first attack linetrace expects a start and an end:
                          Start - where the player is
                          End - where the mouse cursor is

                          But if I'm not aiming at a wall (as you can see in the example images in my previous post) the linetrace just stops, i.e: nothing happens, it doesn't bounce anywhere.
                          That's why I thought I'd increase the End point by multiplying by 5000 would help the linetrace *hit* something on the way to the end point.

                          I don't quite follow what you mean, all positions are already vectors?

                          Originally posted by Mhousse1247 View Post
                          I don't understand well what are you trying to achieve , here is my comprehension :
                          You want to fire a laser in a direction and it will bounce from wall to wall ?
                          It will bounce continuously until it hits a player or the laser has a certain lifetime?
                          Players can shoot a laser.
                          The laser bounces on the walls, and hurts players if they are hit by the laser.

                          It doesn't matter for how long the laser bounces or not, it's just an idea of mine to have a powerup that allows the player to have their laser bounce more times before being destroyed (because it didn't hit any players)...
                          Last edited by Ardoc; 01-04-2016, 09:30 PM.

                          Comment


                            #14
                            Originally posted by DevSaucy View Post
                            The first attack linetrace expects a start and an end:
                            Start - where the player is
                            End - where the mouse cursor is

                            But if I'm not aiming at a wall (as you can see in the example images in my previous post) the linetrace just stops, i.e: nothing happens

                            .....

                            I don't quite follow what you mean, all positions are already vectors?
                            If there is no hit, you need to handle that case by using the "Return Value" of the line trace. If there is no hit, then you need to set the hit point manually to be the end point. Use a "branch" node connected to the return value for that.

                            In terms of "vector vs direction", what I meant is that you cannot multiply a *position* by 5000 in order to 'cast' it out. That will simply scale the position from the origin (0,0,0). To scale a position relative to another position, you need to first subtract the position you wish to scale from. Then you could multiply it by some number and then re-add it to the start position. I usually normalize to have exact control of the casting distance, since if you don't, the scaling will be relative to how long the initial trace vector was which could cause issues in some cases. But yes, technically all positions are vectors, they just aren't relative to your ray so they weren't really being used as directional vectors as it appeared they were meant to be.



                            As I said before, you need to trace to the mouse cursor as the end point and handle the 'no hit' case. If you need the end point to fire offscreen, then you need to convert your position into a normalized direction vector and then you can multiply it by a large number and add it to the starting position to cast it out further. That was the Normalize(start - end) bit from my last post. Hopefully I made things less confusing not more confusing this time.
                            Last edited by RyanB; 01-04-2016, 09:46 PM.
                            Ryan Brucks
                            Principal Technical Artist, Epic Games

                            Comment

                            Working...
                            X