Rotation in UE4 has such complete implementation that it can be hard to choose how to rotate your objects. There are three main methods—FRotator
, FQuat
, and FRotationMatrix
. This recipe outlines the construction and use of the first of the three different methods for the rotation of objects—the FRotator
. Using this, and the following two recipes, you can select at a glance a method to use to rotate your objects.
Have a UE4 project that has an object you can get a C++ interface with. For example, you can construct a C++ class Coin that derives from Actor
to test out rotations with. Override the Coin::Tick()
method to apply your rotations from the C++ code. Alternatively, you can call these rotation functions in the Tick
event from Blueprints.
In this example, we will rotate an object at a rate of one degree per second. The actual rotation will be the accumulated time since the object was created. To get this value, we'll just call GetWorld()->TimeSeconds
.
Actor
class called Coin
.::Tick()
function of the Coin
actor derivative. This will allow you to effect a change to the actor in each frame.FRotator. FRotators
can be constructed using a stock pitch, yaw, and roll constructor, as shown in the following example:FRotator( float InPitch, float InYaw, float InRoll );
FRotator
will be constructed as follows:FRotator rotator( 0, GetWorld()->TimeSeconds, 0 );
FRotator
to your actor using the SetActorRotation
member function, as follows:FRotator rotator( 0, GetWorld()->TimeSeconds, 0 ); SetActorRotation( rotation );
18.223.108.105