Set Actor Rotation depending on Vector

Hey there,
I’m currently struggling on Rotating my pawn according to a given vector in Blueprints.
This Vector represents gravity in my prototype. Normal gravity is represented by Z = -1. Gravity Towards the ceiling would be Z=1, towards a Wall X = 1 /-1 or Y = 1 / -1.
My Custom Gravity is already working, Movement too (except the need of a few additions like not moving in the air, but that’s not part of my problem).

Now I would like to rotate my Pawn accordingly, so it’s feet are facing towards the gravity, but I’m struggling hard understanding how to make a correct rotation out of this vector :frowning:

Here is my current Blueprint: blueprintUE | PasteBin For Unreal Engine 4

Edit:
I Wanted to Add the “Set Actor Rotation” either in the Event Tick, or more likely after the “Trigger Gravity Change” Function

If it’s on a character, then you need to use SetControlRotation.

It’s for a Pawn. I already tried out “Set Actor Rotation” triggered by a key and by setting a fixed rotation which is working as intended.
But for getting the correct rotation from the vector, I’m still struggling.

Thing is, after you’ve rotated the pawn, gravity is always Z=-1, no?

Unless you just rotate the mesh…

No, I trigger a gravity change via button, so (x=0,y=1,z=-1) becomes for example (x=1,y=0,z=0)
That is already working, but I need to rotate the pawn correctly, so it looks like the level has rotated around the player

Ok, it’s easy, just add local rotation.

If you have the pawn like this:

image

then you can always rotate it to that it’s base is facing the current Y direction with

Do you get what I mean?

I don’t know how ‘cubic’ your world is, the code might have to be more subtle…

Thanks for that :slight_smile:
Got it working by adding rotation manually to the Pawn, but I had to add a few more things, so also 180° turns when changing for example from (x=0, y=y, z=-1) to (x=0, y=0, z=1) are covered. But I would also like to add more angles, then I can’t work that way. At least not when the blueprint should be still readably.
That’s why I try to achieve to get the rotation out of the vector.

Currently, I change the gravity direction vector by aiming at a wall.
Then it creates a new gravity direction vector by doing a line trace and using the impact normal, which determines the gravity in my level and “pulls” my pawn in the direction of this gravity.

Normal of the wall is what I was going to say. Your local Z needs to be the same as the wall normal.

1 Like

Ah, now I got what you mean :slight_smile: Thanks a lot :smiley:

Now I’m using “make Rot from Z” with my gravity Vector * -1 and use that rotation with “Set Actor Rotation”.
Alway thought the solution has to be a lot more complex, maybe that’s why my tries never worked :sweat_smile: