• News

• Industries

• Learning & Support

• Community

• Marketplace

# 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.

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.

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.

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!

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?

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.

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!

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

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!

@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??? :eek:

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.

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?

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.

Sorry, make sure to use Normal and not Impact Normal. The Normal from the hitresult is basically the Direction the cube face is facing in. For example if your character was on top of the cube the Normal result would be 0,0,1, if on a side it could be 1,0,0.

I am at work so I cant go into detail but I know Ramas tool can hepl you. other wise

I knew it shouldn’t be as difficult as I made it to be. Using this method will allow for dynamic levels.

ok so ive got the look at rotation from the location my character would be to the hit location. its not exactly working…

im still not entirely sure what you are wanting me to do withe the normal you mentioned. i tried to figure out how i could use the rotation from the normal but never could get anytthing to work.

the following is my current blueprint for getting the new rotation. (marker is where the character center location would be.)

I might honestly need a “explain it like i’m 5” short course from someone who understands vectors and rotations better than I do. @Orkney @SkeetonYu

Let me finish this game onfortnite then ill do a mock up exmaple

So I dont know if this will work…

https://blueprintue.com/render/e4k6ss2e

The get all actors of class node has the surface actor (the cube) , I would suggest not using that node as it fires every frame, just store a reference as a variable. I put it in the construction script here just for this demo but this function does not need to be set every frame, only when the character is moved.

heres a video of it
https://youtu.be/Sn9nLLxV_qg