Announcement

Collapse
No announcement yet.

Turn based strategy on a cube! How to properly rotate actor?

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

    Turn based strategy on a cube! How to properly rotate actor?

    Hello, everyone. I am currently developing a turn-based strategy and one of the core ideas in my game is that it is played on the surfaces of a cube.

    the following figure shows one of my pawns sitting on a corner space of the cube with 4 possible movements he can take highlighted in green.

    Click image for larger version  Name:	Untitled.png Views:	1 Size:	346.6 KB ID:	1466775

    the goal is that when one of the spaces is selected the unit will move to the new space and orient itself correctly based off of the direction it was moving.

    Click image for larger version  Name:	image_136283.png Views:	2 Size:	27.2 KB ID:	1467168

    currently the character will move to a new space fine, but Its orientation is not correct.

    I've tried just getting a look at rotation from the location of the old space and the location of the new space. This works for the spaces on the same side of the cube, but it gives some wonky angled rotations when switching surfaces.

    I am having trouble coming up with a method that will work on every surface of the cube due to the fact that you will be dealing with different axis' on each surface.

    if you have any ideas please let me know. i'm very stuck!



    SOLUTION UPDATE:

    The following is the solution that I found thanks to the help of SkeetonYu and Orkney :


    https://i.gyazo.com/b5b84c866475d828...6e15d3ac23.gif
    as you can see in the GIF i got it to work! I started messing around with each of the "Make Rot from" nodes just to experiment with what happens.

    The Make Rot from Z like was used in Orkney's link (https://blueprintue.com/render/e4k6ss2e) provided really good results. With it i was able to get my unit's feet to always be on the space no matter which side of the cube it was on. At that point i knew i needed to make a Rot from Z so i started to experiment with "Make Rot from ZX" and "Make Rot from ZY".
    When experimenting with ZX I decided to get the Unit Direction Vector from the location of the character on the old space to the location of the new space. I plugged the normal of the line trace into Z and the unit direction vector into X and got my Rotation. It works perfectly!

    Here is the Blueprint for anyone else that may run into something similar later on.

    Click image for larger version  Name:	GetNewRot.png Views:	1 Size:	172.7 KB ID:	1468683
    The Vector math is still a little bit confusing to me. if someone would be willing to go into some detail on what is exactly happening that causes this to work I would be happy to include it in my original post so that maybe it will help anyone else that is running into a similar issue.

    Thanks all!
    Last edited by beanswaggle; 04-30-2018, 04:44 PM.

    #2
    Been working on this on and off for the last couple of hours and I’ve learned that I just do not understand vector math. It’s extremely confusing. Do you guys know if there are any good sources for tutorials on vector math using blueprint?

    Comment


      #3
      I don't know if you tried or not but I find it easier to understand if you play with relative rotation instead. I hope this helps in some way.
      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


        #4
        Originally posted by SkeetonYu View Post
        I don't know if you tried or not but I find it easier to understand if you play with relative rotation instead. I hope this helps in some way.
        Hi SkeetonYu,

        ive messed around with it a little, but mostly with world rotation. What could i do differently using relative rotation to accomplish my goal rather than world rotation?

        ill mess around with relative rotation right now and see if i can get anything working.

        Thanks for your suggestion.
        Last edited by beanswaggle; 04-25-2018, 09:48 PM.

        Comment


          #5
          For example The cube has 6 sides. Change the pawn relative rotation for those sides. I can't do it in my head myself but say for the top part of the cube you keep the pawn relative rotation to 0. Then on the sides you would change the relative pitch to 90(sideways). Then on the bottom you change the relative pitch to 180(upside down i think) and so on.
          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


            #6
            Originally posted by SkeetonYu View Post
            For example The cube has 6 sides. Change the pawn relative rotation for those sides. I can't do it in my head myself but say for the top part of the cube you keep the pawn relative rotation to 0. Then on the sides you would change the relative pitch to 90(sideways). Then on the bottom you change the relative pitch to 180(upside down i think) and so on.
            I understand what you are saying but unfortunately its not as easy as just setting their relative location. the issue is that which space the character is moving is very dynamic. in the image I posted the pawn has 4 space options that it can move to. each of those options requires a completely different rotation of the pitch, yaw, and roll.

            I need to be able to determine how the pawn needs to rotate just with the information provided such as the location and rotation of the pawn, old space, new space, etc. i do not think i will be able to solve my problem with hard coded values for each side of the cube. Maybe I am wrong and am looking at this problem incorrectly.

            I hope this helps explain a little more of what my issue currently is.

            Thank you SkeetonYu!

            Comment


              #7
              Just drew up a little bit of an example to be further descriptive of my issue.

              Comment


                #8
                Click image for larger version

Name:	TheCube.gif
Views:	27
Size:	303.3 KB
ID:	1467370

                So I made my own project just to figure this out and well I got it working... but its a really bad work around I think and its mainly hardcoded. I'm uploading the project files to my google drive for you.
                Last edited by SkeetonYu; 04-26-2018, 09:03 PM. Reason: Added gif
                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
                  Originally posted by SkeetonYu View Post

                  So I made my own project just to figure this out and well I got it working... but its a really bad work around I think and its mainly hardcoded. I'm uploading the project files to my google drive for you.
                  holy **** man! thanks! ill take a look at that right now!

                  Comment


                    #10
                    Originally posted by beanswaggle View Post

                    holy **** man! thanks! ill take a look at that right now!
                    SkeetonYu

                    alright so after reviewing your sample project here are my thoughts. this seems like it will work. the issue is the hardcoded rotation axis for each space. The main reason im having an issue is that each of these spaces have the possibility to shift, move, and rotate. so one turn that specific space might be on the XY axis and the next turn it might be on the XZ Axis. so everything you have done in your example will work besides the hardcoded rotation axis.

                    although I have learned from this that the only information ill need is what rotation axis it lies on to determine the appropriate rotation of the pawn.

                    This does have me thinking... is there a way i could determine the rotation axis based off of where each space is in relation to the center of the cube???

                    Comment


                      #11
                      Originally posted by beanswaggle View Post
                      SkeetonYu

                      alright so after reviewing your sample project here are my thoughts. this seems like it will work. the issue is the hardcoded rotation axis for each space. The main reason im having an issue is that each of these spaces have the possibility to shift, move, and rotate. so one turn that specific space might be on the XY axis and the next turn it might be on the XZ Axis. so everything you have done in your example will work besides the hardcoded rotation axis.

                      although I have learned from this that the only information ill need is what rotation axis it lies on to determine the appropriate rotation of the pawn.

                      This does have me thinking... is there a way i could determine the rotation axis based off of where each space is in relation to the center of the cube???
                      I think you can if you find the rotation using forward vector and right vector. That should give you the direction of each square and use that to determine which axis to use.
                      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


                        #12


                        Originally posted by SkeetonYu View Post

                        I think you can if you find the rotation using forward vector and right vector. That should give you the direction of each square and use that to determine which axis to use.
                        Im not very knowledgeable when it comes to vector and rotator math. so what you are describing is kind of going over my head. How does having a direction help me determine which axis to use?


                        Just thinking about it out loud, all of the spaces on a rotation axis should have the exact same rotation on at least 2 of pitch, yaw, and roll. So in reality as long as I know what the rotation for each axis is I can just preform a check to see which rotation-axis rotator the space rotator matches. It is going to be slightly hard-coded, but that shouldn't matter since I know for a fact there will only ever be 6 axes.

                        At least in my head that makes sense. This might have been what you were trying to get me to try from the beginning. I am just having trouble wrapping my mind around all of this, but i am putting it together slowly.
                        Last edited by beanswaggle; 04-27-2018, 03:05 AM.

                        Comment


                          #13
                          When you place the character in the correct place above the surface, Fire a LineTrace towards the cube, get the hit location of the hit on the cube surface.


                          use FindLookAtRotation from the centre of your character to the location supplied from the Line Trace.

                          Failing that get the Hit Normal of the line trace and use that instead.

                          This would not need to be hardcoded and would work on surfaces that were not 90 degree
                          My Game Frontier Devblog HERE

                          Comment


                            #14
                            Originally posted by Orkney View Post
                            When you place the character in the correct place above the surface, Fire a LineTrace towards the cube, get the hit location of the hit on the cube surface.


                            use FindLookAtRotation from the centre of your character to the location supplied from the Line Trace.

                            Failing that get the Hit Normal of the line trace and use that instead.

                            This would not need to be hardcoded and would work on surfaces that were not 90 degree
                            what do I do with the normal I would get from the line trace?

                            Comment


                              #15
                              Originally posted by beanswaggle View Post



                              Im not very knowledgeable when it comes to vector and rotator math. so what you are describing is kind of going over my head. How does having a direction help me determine which axis to use?


                              Just thinking about it out loud, all of the spaces on a rotation axis should have the exact same rotation on at least 2 of pitch, yaw, and roll. So in reality as long as I know what the rotation for each axis is I can just preform a check to see which rotation-axis rotator the space rotator matches. It is going to be slightly hard-coded, but that shouldn't matter since I know for a fact there will only ever be 6 axes.

                              At least in my head that makes sense. This might have been what you were trying to get me to try from the beginning. I am just having trouble wrapping my mind around all of this, but i am putting it together slowly.
                              Well, you just need the X axis and Y axis of the square and find the direction they pointing. There's a pattern you can see with my gif. The square on the side has its X axis pointing toward the same direction as world X. But the Y axis of it is facing down. So with that information we can determine that it'll be used with XZ axis.

                              I'm not on my PC but hoping this can help you in some way.

                              I said Foward Vector as that gives the X direction and Right Vector as it gives the Y direction. But you probably can find that just by getting it's rotation.

                              This is all a theory I haven't test anything. But using the square patterns you should be able to determined something.
                              Last edited by SkeetonYu; 04-27-2018, 10:48 AM.
                              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

                              Working...
                              X