FRotator Rotation Direction?

Hi everyone,

How are we all doing? I hope that you are well.

I have been following along the FRotator lecture, I am currently at around 5:38 in the video, which is where Sam is about to set a challenge.

Not only that, but I had previously already changed up my cubes to be spheres instead. Likewise, I was then patiently waiting for the FRotator lecture, in the hope that it would aid me, and point me in the right direction of making the spheres rotate as they move, which they now do. (Kinda, as can be seen below).

sphere-rotation-compressed

However, of course, they only rotate in one direction. The way I have the spheres set up, is the same way in which we set up the cubes earlier on, which is to traverse left and right, (or forward and backward if you so wish).

I thought that a simplistic way to solve this so that it would reverse the rotation direction might be to just follow suit with what we did for changing the velocity of the platform. Where in the MovePlatform() function, we just simple set PlatformVelocity = -PlatformVelocity;. So naturally, I assumed we could simply do something like: RotationVelocity = -RotationVelocity;! However, this returns a nice little error: no operator "-" matches these operands.

So my questions are:

“Is there a simple way in which this can be achieved?”

“Would we be better off using a vector so that we can manipulate the value to be negative?”

“Would we be better off adding some conditional logic to the blueprint itself that perhaps checks to see if the MoveDistance has been reached, if so then update the value”

Note: I guess in this scenario, we could maybe set up a boolean variable as a flag that toggles between true and false based on if the Move Distance is Greater or Less than. Then we could probably use a branch to check that flag and set the RotationVelocity accordingly?

Look forward to hearing every one’s thoughts on this. Apologies if it is covered later on.

Kind Regards
David

1 Like

GetInverse() is probably what you’re after.

Is there anything wrong with modifying it in the Move function at the same time you modify the direction to go in?

1 Like

Sorry, This was referring to the final question, as in, if we were to implement it directly in the blueprint, then this might be a good approach to take. I was unable to do it directly in the move function because as stated above, the FRotator doesn’t allow you to set it to a negative value:

RotationVelocity = -RotationVelocity; - this returns a nice little error: no operator "-" matches these operands.

In regard to the GetInverse(); it works as expected, although at first I thought it wasn’t working as it would only roll way one then slide the other. I realised having values set to 360 and -360 were causing the issue, so I switched them both out for 180, and it solved the problem. As can be seen below:

getinverse

This solution will do for now.

I have to say, though, a half rotation for the full length of the island doesn’t look as appealing as the full 360-degree rotation. The issue if I use GetInverse() is that it sets the rotation to 0 for the inverse. Is there any way to specify the inverse values? I saw there were a couple of Clamp functions and actually a RotateVector and UnrotateVector function, could these be used?

Kind Regards
David

1 Like

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

Privacy & Terms