forked from Harrison1/unrealcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotatingActor.cpp
More file actions
44 lines (32 loc) · 1.24 KB
/
RotatingActor.cpp
File metadata and controls
44 lines (32 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Harrison McGuire
// UE4 Version 4.20.2
// https://github.com/Harrison1/unrealcpp
// https://severallevels.io
// https://harrisonmcguire.com
#include "RotatingActor.h"
// Sets default values
ARotatingActor::ARotatingActor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
PitchValue = 0.f;
YawValue = 0.f;
RollValue = 0.f;
}
// Called every frame
void ARotatingActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
// on every frame change rotationg for a smooth rotating actor
FQuat QuatRotation = FRotator(PitchValue, YawValue, RollValue).Quaternion();
AddActorLocalRotation(QuatRotation, false, 0, ETeleportType::None);
// You will want to set rotation with Quanternions and not Rotation values
// The below method causes a bug for the pitch value. The pitch value stops updating at 90 degrees due to Gimbal Lock
// FRotator NewRotation = GetActorRotation();
// NewRotation.Pitch += PitchValue;
// NewRotation.Yaw += YawValue;
// NewRotation.Roll += RollValue;
// OR add values using the FRotator Add function
// FRotator NewRotation = GetActorRotation().Add(PitchValue, YawValue, RollValue);
// SetActorRotation(NewRotation);
}