How to round rotation angle up or down?


I have a player that is able to push a box in the player controller’s direction which works fine.

This box should be pushable only along the x and y axes which means I have to round the angle up/down to the next 0, 90, or -90 degrees e.g.

How can I do that?

Do it by vectors not angles, vectors are usually easier. Or post your setup for it.
Most of the time weird rotation calculations can be avoided.


Hey, this is how I set it up

Any ideas?

Whats wrong with your setup?

The player is able to push the object in the direction of the player controller which works fine.

I want the object to move along the x and y axes only though. For that I’d have to round the angle up or down ( to the next 0, 90 or -90 degrees).

How can I do that? I looked a bit into floor and ceil but will they work for me here?

Just break the vectors going into delta location and only plug into the X and Y components, keeping Z at 0.

Are you saying that you want the box to move just along X, or just along Y, but not both at the same time? Like pushing a square block along a grid (seen in games like tomb raider/zelda etc).

Yeah, exactly. That’s what I want to do (just from a FP Perspective).

Thanks for your input Shirk, I will see how it goes.

@Shirk: This was probably your answer on how to constrain to the x and y axes but this is not the solution to my problem. Thanks anyhow, much appreciated :slight_smile:

If you’re just dealing with a cube (or cube collision), you should be able to use the impact normal for this. Just reverse the impact normal, and then push the box in that direction (multiplied by whatever magnitude).

Screenshot of my little test below, seems to work ok :slight_smile: (blockyblock is the name of the box blueprint i made to test)

Hey, thank you!!! This seems to work fine…! Although I can move some objects only in one or two directions (as opposed to four). Gotta do a bit of testing on that. Again, thank you!