• News

• Industries

• Learning & Support

• Community

• Marketplace

# Planets, moons and suns: trying to make stuff orbit other stuff

The simplest way I’ve been able to make something orbit something else is by giving it a Rotating Movement component and moving its pivot around. However, this means the planet does exactly one rotation per orbit, which looks really bad. Also, I haven’t found a way to attach a pivot point to anything; I don’t know if it’s possible.

In blueprint, I tried to make a script that updates a direction vector from the locations of the star and planet, rotates it 90 degrees on the X axis, and moves the planet along it every tick. Unfortunately, I apparently don’t know the proper way of moving things along changing vectors, because the script I came up with just makes the planet go off in a line. Here’s what I came up with:

http://i.imgur.com/rTkp72wl.png

I want to make an actor class for planets or moons that starts rotating and orbiting a parent actor when spawned, but I have to figure out how to make an actor orbit correctly first.

I haven’t looked that deep into it but you can try something really simple like this:

Then all you have to do is add a relative rotation to the yaw of the SpringArm and the little planet will orbit the big one (although that would be a perfect circle orbit :p).

You could use a constraint. Heres a link to it in the docs:

This way would be perfect for circular orbits, but not so good for elliptical. You can specify a single axis to constrain to and give your object an initial velocity. Turn off gravity for your object and it should orbit indefinatly in a perfect circle.

SPM Base Mesh is rotation origin.
Can be done with no casting, of course.

https://dl.dropboxusercontent.com/u/96577365/UE4/Untitled.jpg

All above solutions are either inefficient or much too complicated. TkMasters solution comes closest except that there is no need for a springarm.

You simply need to attach your planet to a dummy object (sprite or such) at the pivot point position. You then rotate that pivot object with a simple Set World/local Rotation, and the planet will follow without any of the above calculations.

I will be releasing the Solus sky soon, so you can have a look how I did it.

You can attach objects in BP by dragging one component onto another in the component editor.

Blueprints make it look complicated/inefficient:

Same in code:

``````
m_fOrbCurrent = m_fOrbCurrent + m_fOrbSpeed;
m_fPos.x = sin(m_fOrbCurrent)*m_nOrbDistance;
m_fPos.z = cos(m_fOrbCurrent)*m_nOrbDistance;

``````

I’d still like to see a more elegant solution, though. So please keep up us updated.
Site looks quite epic, btw.

Why is this so hard to do? I just want one actor to orbit around another, my god. This is ridiculous.

This is not hard, this stuff can be done in 10 or more ways. Your first post idea is right spot on. But learn vector math.
No wonder that your planets go in straight lines when you add increasing values to their X coordinate.
Instead adding orbit Velocity to X coordinate of resulting vector, get game seconds since beginning of play multiply it by some delta time, and feed that to Angle in rotate vector (you can calculate modulo 360 of it).

Btw. Axis should be [1,0,0] there (in rotate vector), luckily epic usually normalizes all those vectors as safeguard (but for eg dot product does not and produces funky results).

PS. do not add actor local transform, instead set actor world location, or relative location.