Download

Rotating a Actor around (0.f,0.f,0.f)

Hello,

I started working with the Unreal engine a little time ago and have now a really basic Problem.

I want to create a really simple solar system.
A Sun and some Planets rotating around the Sun.
And here is my Problem. How do I create the rotation of my Planets around the Sun in C++ ?

In the last Engine, I worked with, I would just Multiply my Rotation matrix with the Matrix of my Planet and as long as I don’t translate it back to the centre before I do this, the Planet should Rotate around the Centre.

So is there a simple Actor function to achieve this in the unreal Engine ?

Thank you for your Time.

Typically you would use some type of set location for this.

Well without more detail, I’d say that you could just add the other planets as actor components & use relative rotation.
Otherwise, get your math hat on, then use the static FMath::* methods to perform some basic trigonometry.

Likewise, without having tested it, you could probably do something like this:


auto RotationAroundSun = FRotator(0.f, 0.f, 45.f);
auto OriginOfSun = FVector::ZeroVector;
auto DistanceFromSun = 300.f;
auto PlanetLocation = OriginOfSun + (RotationAroundSun.Vector() * DistanceFromSun);
Planet.SetActorLocation(PlanetLocation);


But by far the easiest route would be to just have other planets be actor components, use a USpringArmComponent to set the distance, and just set the relative rotation to whatever you want.