Announcement

Collapse
No announcement yet.

Get new vector based on angle of two vectors

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

    Get new vector based on angle of two vectors

    I feel like I am missing something simple here, I thought if I had two world space vectors I could grab the angle between them either with 'Find Look At Rotation' and breaking the rotator to get the yaw or by getting the degrees from normalizing the two vectors, getting the dot product, then the arccos. It does appear to give me the correct angle.

    But then how do I make a vector based off that angle?

    I tried to use 'Rotate Vector Around Axis' and give it the world space vector and axis set to 1.0 in Z.

    The result I get is not something that is making sense to me, not sure how to even explain it other than to say it is definitely not what I need. My brain is too fried to think much now.

    Here is an image of what I am trying to do:

    I have A location vector, and I have B location vector, I get the angle between (white line) and want to make a vector off in the distance (above B / the black line).

    Click image for larger version

Name:	vectora.jpg
Views:	1
Size:	57.4 KB
ID:	1141121

    #2
    Hello,
    i remember another thread where something like this have been solved by using " get forward vector." Maybe it will work for you too.

    Edit : like in this example for a line trace from : https://docs.unrealengine.com/latest...nts/index.html
    Last edited by Fen; 11-23-2014, 06:50 AM.

    Comment


      #3
      Well you have two locations A and B. To find the vector that goes from A to B and continues on into the distance, all you need to do is take B - A (subtraction). This is basically what a line trace does.
      Last edited by JGrady1206; 11-23-2014, 03:39 PM.

      Comment


        #4
        Originally posted by Fen View Post
        Hello,
        i remember another thread where something like this have been solved by using " get forward vector." Maybe it will work for you too.

        Edit : like in this example for a line trace from : https://docs.unrealengine.com/latest...nts/index.html
        I have two vectors, that example uses an object to get a forward vector. How do I get the forward vector of a vector?

        Originally posted by JGrady1206 View Post
        Well you have two locations A and B. To find the vector that goes from A to B and continues on into the distance, all you need to do is take B - A (subtraction). This is basically what a line trace does.
        Not sure what you're getting at.. it is most certainly not what the line trace does.

        Click image for larger version

Name:	bnega.jpg
Views:	1
Size:	111.4 KB
ID:	1061378

        Comment


          #5
          Originally posted by Vaei View Post
          I have two vectors, that example uses an object to get a forward vector. How do I get the forward vector of a vector?



          Not sure what you're getting at.. it is most certainly not what the line trace does.

          [ATTACH=CONFIG]18010[/ATTACH]
          Sorry - I'm not saying that's what it does completely. What I recommend is brushing up a bit on 3D math and start with the basics like points and vectors in 3d space. Leave the game alone for a moment and think simple, then once you're able to find the solution in a simple setting then you can then tailor that toward your liking in the game. Obviously I can't solve your problem completely without knowing all of things you have going on underneath so I apologize if what I said is not giving you exactly what you need. Anyways good luck!

          Comment


            #6
            I'm not implying that's all it does, I'm implying that subtracting vector B from vector A isn't what a line trace does, otherwise the line in the image would point at B.

            If I make a line trace with debug, it draws it from A->B.

            There's nothing really going on under the hood that'd change that. I have two world space vectors and that's pretty much it.

            Comment


              #7
              How do I get the forward vector of a vector?
              A vector always points "forward" to some direction

              Anyways, to answer your first post.. what you want to do is subtract vector A from B then normalize the result (which is going to give you the direction with a length (aka magnitude) of 1) then you can multiply that with whatever distance you want to "extend" the line to and finally you add the result of that to either vector A or B (depending on what you want the starting point to be).

              So in more programing terms the formula is: normalize(VectorB - VectorA) * DistanceFloat + VectorB

              It would be a good idea to look into some basic vector math though, you can start here and also legacy unreal wiki here

              4.10 Update! -> [Community Project] WIP Weather & Ocean Water Shader
              WIP Interactive Water Shader, WIP 2D Water Sim
              WIP FFT Ocean w/ Foam, Quad-tree Infinite Ocean LOD

              Comment


                #8
                Originally posted by TK-Master View Post
                A vector always points "forward" to some direction

                Anyways, to answer your first post.. what you want to do is subtract vector A from B then normalize the result (which is going to give you the direction with a length (aka magnitude) of 1) then you can multiply that with whatever distance you want to "extend" the line to and finally you add the result of that to either vector A or B (depending on what you want the starting point to be).

                So in more programing terms the formula is: normalize(VectorB - VectorA) * DistanceFloat + VectorB

                It would be a good idea to look into some basic vector math though, you can start here and also legacy unreal wiki here
                Thanks for taking the time to respond. I'm not certain if I'm doing it correctly, does this look right? Changing the Distance float isn't reducing or increasing the length, if it does anything sometimes it just changes the direction.

                Click image for larger version

Name:	badv.jpg
Views:	1
Size:	235.2 KB
ID:	1061379

                I will elaborate on my purpose in case of other methods..

                When my character is near something, it will find each corner of the static mesh and store it as a vector array. My Update Position event will look at each vector in the array and exclude any corners that are not visible by doing a line trace from the character to the corner to see if it hits anything, if it hits something it can't see it. However, since it's tracing directly onto the corner it always hits something so I need to reduce the length of the vector by around 1-2% so that it wont hit the object if the corner isn't occluded.

                If there's 3 vectors remaining, it also excludes the closest to the character. This gives me the two edges required for the last point on the mesh that the character can actually see.
                Last edited by Vaei; 11-23-2014, 06:59 PM.

                Comment


                  #9
                  I think you're getting confused by the fact that Line Trace draws between two coordinates in world space, while this vector(B-A) is not a world location. A mathematical vector does not have an origin, it is just a direction and a magnitude, which means that when you plug in the result B-A, it will appear as if you're drawing towards the center of the world. This is because you're still treating it as a world location. For the trace to behave properly, you will have to do this:

                  Start: World location of Object
                  End: World location of Object + Vector(B-A)

                  Try the trace mentioned above, but where world location is from different objects. It will make more sense then.

                  Click image for larger version

Name:	TraceExample.jpg
Views:	1
Size:	158.0 KB
ID:	1061383

                  Edit*
                  To clarify. In programming, a vector is just how to store some values. In math, a coordinate and a vector is NOT the same thing. While the values may look identical, they have different purposes. In programming it's all a matter of how we use values, so we can cheat. So a vector can be used as a coordinate, and a coordinate can be used as a vector. Mathematicians cry, but we can have fun with it. Keep this in mind.
                  Last edited by Denny; 11-23-2014, 08:55 PM.
                  www.dennylindberg.com - My RnD / WIP thread
                  Mortal Online 2 - Kitten'd - Guardians of Valor (Android, iOS)

                  Comment


                    #10
                    Originally posted by Vaei View Post
                    I'm not certain if I'm doing it correctly, does this look right?...
                    Nope! that's incorrect.. you should multiply the result of the Normalize node with a float number (not a vector!) then add that to vector B.

                    Example:
                    Click image for larger version

Name:	vectorExample.jpg
Views:	1
Size:	87.6 KB
ID:	1061382

                    4.10 Update! -> [Community Project] WIP Weather & Ocean Water Shader
                    WIP Interactive Water Shader, WIP 2D Water Sim
                    WIP FFT Ocean w/ Foam, Quad-tree Infinite Ocean LOD

                    Comment


                      #11
                      Originally posted by Denny View Post
                      I think you're getting confused by the fact that Line Trace draws between two coordinates in world space, while this vector(B-A) is not a world location. A mathematical vector does not have an origin, it is just a direction and a magnitude, which means that when you plug in the result B-A, it will appear as if you're drawing towards the center of the world. This is because you're still treating it as a world location. For the trace to behave properly, you will have to do this:

                      Start: World location of Object
                      End: World location of Object + Vector(B-A)

                      Try the trace mentioned above, but where world location is from different objects. It will make more sense then.
                      Indeed, I've also struggled with this at first. So to clarify (and anyone please correct me if I'm wrong):

                      There are two types of vectors in UE4 (and probably most other engines). One is the mathematical that has only magnitude (length) and direction. This one does not have a location. You can place that same vector anywhere in space. You can picture it as an arrow pointing somewhere. Neither starting nor end point of that arrow denotes an actual location. You could call this a direction vector.

                      The other kind of vector is a location vector. Technically it isn't a vector at all, it just uses FVector as a type to store X, Y, Z values in. It's just a point in space without direction or length.

                      Comment


                        #12
                        Originally posted by TK-Master View Post
                        Nope! that's incorrect.. you should multiply the result of the Normalize node with a float number (not a vector!) then add that to vector B.
                        Ah, thanks! For some reason my brain put parenthesis around the "DistanceFloat + VectorB". This works perfectly. I've bookmarked the vector math pages you linked and I'll either find time to get into them later or do it before my next attempt to calculate vectors.

                        Thanks a lot everyone for taking the time to help me out.

                        It seems most of my problems arise from the dilemma of needing to get stuff done and being brain fried from spending too much time attempting to get stuff done.

                        Comment


                          #13
                          Originally posted by Gigantoad View Post
                          There are two types of vectors in UE4 (and probably most other engines). One is the mathematical that has only magnitude (length) and direction. This one does not have a location. You can place that same vector anywhere in space. You can picture it as an arrow pointing somewhere. Neither starting nor end point of that arrow denotes an actual location. You could call this a direction vector.

                          The other kind of vector is a location vector. Technically it isn't a vector at all, it just uses FVector as a type to store X, Y, Z values in. It's just a point in space without direction or length.
                          Indeed! Both types are stored in the same data type as the elements are only 2-3 floats. The magnitude is then returned by calculating the length, using sqrt(x*x, y*y, z*z) (Pythagoras). Square root is a relatively expensive operation, so it's redundant to calculate and store it for all vectors, and is only calculated when needed. It's up to us to remember what type of value we're working with when we're getting and setting a vector. It could be both a location and vector at the same time, depending on what we're up to.

                          I hope we're not going too off-topic Vaei. It's just for future reference if other users end up in your thread. Good luck with your project.
                          www.dennylindberg.com - My RnD / WIP thread
                          Mortal Online 2 - Kitten'd - Guardians of Valor (Android, iOS)

                          Comment


                            #14
                            Originally posted by Vaei View Post
                            Ah, thanks! For some reason my brain put parenthesis around the "DistanceFloat + VectorB". This works perfectly. I've bookmarked the vector math pages you linked and I'll either find time to get into them later or do it before my next attempt to calculate vectors.

                            Thanks a lot everyone for taking the time to help me out.
                            Glad I could help, this vector stuff used to fry my brain too back in the day when I was starting out, but when I eventually got the basics clearly in my head it's a piece of cake.

                            Originally posted by Gigantoad View Post
                            Indeed, I've also struggled with this at first. So to clarify (and anyone please correct me if I'm wrong):

                            There are two types of vectors in UE4 (and probably most other engines). One is the mathematical that has only magnitude (length) and direction. This one does not have a location. You can place that same vector anywhere in space. You can picture it as an arrow pointing somewhere. Neither starting nor end point of that arrow denotes an actual location. You could call this a direction vector.

                            The other kind of vector is a location vector. Technically it isn't a vector at all, it just uses FVector as a type to store X, Y, Z values in. It's just a point in space without direction or length.
                            Not exactly! there are no two kind of vectors (well there is vector2d with just X & Y but that's another story) every vector has a direction and a magnitude! what you are probably referring to by "direction vector" is a normalized vector (a vector with a length (magnitude) of 1).. and the "location vector" obviously has a direction and length too!

                            4.10 Update! -> [Community Project] WIP Weather & Ocean Water Shader
                            WIP Interactive Water Shader, WIP 2D Water Sim
                            WIP FFT Ocean w/ Foam, Quad-tree Infinite Ocean LOD

                            Comment


                              #15
                              Originally posted by Denny View Post
                              Indeed! Both types are stored in the same data type as the elements are only 2-3 floats. The magnitude is then returned by calculating the length, using sqrt(x*x, y*y, z*z) (Pythagoras). Square root is a relatively expensive operation, so it's redundant to calculate and store it for all vectors, and is only calculated when needed. It's up to us to remember what type of value we're working with when we're getting and setting a vector. It could be both a location and vector at the same time, depending on what we're up to.

                              I hope we're not going too off-topic Vaei. It's just for future reference if other users end up in your thread. Good luck with your project.
                              No such thing as off-topic when it comes to learning new things. It pertains to me also, since I came from 3D art and my understanding of a vector was an XYZ coordinate on a graph I was unaware of the magnitude/direction of a vector. Now things make a lot more sense!

                              Originally posted by TK-Master View Post
                              Glad I could help, this vector stuff used to fry my brain too back in the day when I was starting out, but when I eventually got the basics clearly in my head it's a piece of cake.


                              Not exactly! there are no two kind of vectors (well there is vector2d with just X & Y but that's another story) every vector has a direction and a magnitude! what you are probably referring to by "direction vector" is a normalized vector (a vector with a length (magnitude) of 1).. and the "location vector" obviously has a direction and length too!
                              I think my brain fries regardless of what I'm trying to solve I have spent days on the system I'm working on and its getting tedious so it definitely adds up. But with this I can move to the next phase, I am very grateful for the assistance.

                              For the sake of argument, isn't a quaternion stored in a vector4? I guess that's a dangerous question to ask here

                              Comment

                              Working...
                              X