This component is similar to RotatingMovementComponent
in that it is designed to make the components parented to it move in a particular way. In this instance, it will move any attached components in an orbit around a fixed point at a fixed distance.
This could be used, for example, for a shield that orbits around a character in an Action RPG.
Create a new
SceneComponent
subclass and add the following properties to the class declaration:UPROPERTY() bool RotateToFaceOutwards; UPROPERTY() float RotationSpeed; UPROPERTY() float OrbitDistance; float CurrentValue;
Add the following to the constructor:
RotationSpeed = 5; OrbitDistance = 100; CurrentValue = 0; RotateToFaceOutwards = true;
Add the following code to the
TickComponent
function:float CurrentValueInRadians = FMath::DegreesToRadians<float>(CurrentValue); SetRelativeLocation(FVector(OrbitDistance * FMath::Cos(CurrentValueInRadians), OrbitDistance * FMath::Sin(CurrentValueInRadians...