Rolling a cube in Unreal

Hello,

I am trying to roll a cube in Unreal but I am not able to do it. For visualization purpose I am creating something similar to this : https://www.youtube.com/watch?v=3nFpUDAzysY

For this I attached a URotatingMovementComponent and tried to offset the pivot in order to rotate it.
I have attached the code that does it. But it does not work.

Resetting the rotation after 1 second
TimerFunction

Addition of Rotating Component

Function that rotates up when the “Up” button is clicked

Doesn’t work how?

It looks like this
Red sphere is the position of pivot point

https://imgur.com/nxNnh0f

How are you drawing the sphere? Are you sure it isn’t using local space?

Its just a small bit of code.
I am just passing in the location of the pivot directly as the center of the spare

I have commented it out recently
image

Sorry for the late response

I’ve never used this component but I don’t think you’re using it correctly as you are using the world location in the pivot translation.

However I just added them to a couple cube’s in the map and used the same pivot translation for them and they all rotated the same way.

How can I use the local position of the cube in pivot translation?
What should I change in the script?

Thank You for helping out

Well assuming the pivot of the cube is in the centre as it is for the Cube in the Shapes menu. A pivot translation of X = 50, Y = 0, Z = -50 should rotate it as you want forwards.

Yeah it should
But when I reset the pivot and position it back after the player clicks the button again it just rotates the cube around the same pivot location as earlier

So I found a tutorial and made a bit of progress but now I am stuck with how to use the timer function.
In the tutorial the person is moving the cube with Move Tween Function. Move Tween is being called in the Start Moving Function inside a Timer. All this is being called in the Event graph

Event Graph

Start Moving

Move Tween

Pivot Point

In my code I am also going the same, but when I do my cube moves both in Y and Z Axis. This only happens when I implement the step thing to make the timer execute it in steps. Otherwise the code works fine

My Code

I think it would be easier to take a look at your project

So would you mind sending me your project using the following link?

https://gdev.tv/projectupload

Please use File > Zip Project within Unreal as this will ensure only required files are zipped up and things like the Binaries are excluded.

Thank you for offering help and time
I really appreciate it
Actually I got reply from the unreal community and this solution worked

As for the code there were places where I did not have to set the Actor location. I fixed that and the alternate solution also worked

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms