Black Holes, Orbiting Bodies, and Anomalies -- Oh my!
Greetings all -
I'm fairly new to lua scripting, but am excited about the possibilities of doing so for Empty Epsilon. One of the cool things I discovered with EE was the ability to have space bodies in motion - because of course space is a lot more fun when you have things moving around! So I started experimenting with what could be done, and thought maybe others might like to use as well. I will add snippets here as I'm able.
First up, I wanted to try planets orbiting a black hole at different rates, that had moons that also had moons themselves. Here's what I came up with:
Because all the code in init() follows the constructs already established in EE, no additional code is needed in the update() function.
Enjoy!
I'm fairly new to lua scripting, but am excited about the possibilities of doing so for Empty Epsilon. One of the cool things I discovered with EE was the ability to have space bodies in motion - because of course space is a lot more fun when you have things moving around! So I started experimenting with what could be done, and thought maybe others might like to use as well. I will add snippets here as I'm able.
First up, I wanted to try planets orbiting a black hole at different rates, that had moons that also had moons themselves. Here's what I came up with:
function init()
-- BLACK HOLE ORBITING SYSTEM TEST
-- initial alignment of objects is along the X axis (X value is the same; Y changes for distance from center)
-- the center object
center_blackhole = BlackHole():setPosition(0, 0)
-- "on the edge" planet orbiting just outside the event horizon, very fast
cbh_event_horizon1 = Planet():setPosition(0, -6000):setPlanetRadius(500)
:setDistanceFromMovementPlane(-2000)
:setPlanetSurfaceTexture("planets/planet-1.png")
:setPlanetCloudTexture("planets/clouds-1.png")
:setPlanetAtmosphereTexture("planets/atmosphere.png")
:setPlanetAtmosphereColor(0.2,0.2,1.0)
cbh_event_horizon1:setOrbit(center_blackhole, 5)
-- "near the edge" planet orbiting near the event horizon, fast
cbh_event_horizon2 = Planet():setPosition(0, -10000):setPlanetRadius(1000)
:setDistanceFromMovementPlane(-2000)
:setPlanetSurfaceTexture("planets/planet-1.png")
:setPlanetCloudTexture("planets/clouds-1.png")
:setPlanetAtmosphereTexture("planets/atmosphere.png")
:setPlanetAtmosphereColor(0.2,0.2,1.0)
cbh_event_horizon2:setOrbit(center_blackhole, 15)
-- planetary orbital sub-system 1, to the 'north' of sun1
cbh_main_planet1 = Planet():setPosition(0, -30000):setPlanetRadius(3000)
:setDistanceFromMovementPlane(-2000):setAxialRotationTime(30)
:setPlanetSurfaceTexture("planets/planet-1.png")
:setPlanetCloudTexture("planets/clouds-1.png")
:setPlanetAtmosphereTexture("planets/atmosphere.png")
:setPlanetAtmosphereColor(0.2,0.2,1.0)
cbh_main_planet1:setOrbit(center_blackhole, 300)
-- orbiting bodies for cbh_main_planet1, inner to outer
mp1_satelite1 = Planet():setPosition(0, -24000):setPlanetRadius(500)
:setDistanceFromMovementPlane(-2000):setAxialRotationTime(30)
:setPlanetSurfaceTexture("planets/planet-1.png")
:setPlanetCloudTexture("planets/clouds-1.png")
:setPlanetAtmosphereTexture("planets/atmosphere.png")
:setPlanetAtmosphereColor(0.2,0.2,1.0)
mp1_satelite1:setOrbit(cbh_main_planet1, 10)
mp1_satelite2 = Planet():setPosition(0, -20000):setPlanetRadius(1000)
:setDistanceFromMovementPlane(-2000):setAxialRotationTime(30)
:setPlanetSurfaceTexture("planets/planet-1.png")
:setPlanetCloudTexture("planets/clouds-1.png")
:setPlanetAtmosphereTexture("planets/atmosphere.png")
:setPlanetAtmosphereColor(0.2,0.2,1.0)
mp1_satelite2:setOrbit(cbh_main_planet1, 60)
mp1s2_satelite1 = Planet():setPosition(0, -18000):setPlanetRadius(200)
:setDistanceFromMovementPlane(-2000):setAxialRotationTime(10)
:setPlanetSurfaceTexture("planets/planet-1.png")
:setPlanetCloudTexture("planets/clouds-1.png")
:setPlanetAtmosphereTexture("planets/atmosphere.png")
:setPlanetAtmosphereColor(0.2,0.2,1.0)
mp1s2_satelite1:setOrbit(mp1_satelite2, 5)
mp1_satelite3 = Planet():setPosition(0, -16000):setPlanetRadius(500)
:setDistanceFromMovementPlane(-2000):setAxialRotationTime(30)
:setPlanetSurfaceTexture("planets/planet-1.png")
:setPlanetCloudTexture("planets/clouds-1.png")
:setPlanetAtmosphereTexture("planets/atmosphere.png")
:setPlanetAtmosphereColor(0.2,0.2,1.0)
mp1_satelite3:setOrbit(cbh_main_planet1, 60)
end
Because all the code in init() follows the constructs already established in EE, no additional code is needed in the update() function.
Enjoy!
Comments
And for good measure, I added a planet orbiting one of the BH's and a huge space station orbiting the other! (Yes, this is how you can have stations orbiting other entities.)
Please note that I've hard coded the orbital speed to something that's easy to observe for a test. You may want to slow the speed down a bit… otherwise the people inhabiting the space station might be crushed to goo from the G forces… ;]
Note that you create the bodies in the init() function, then move them in the update(delta) function.
Also note that you must "require("utils.lua")"
Add the following in the update() function.
Enjoy!
Note that you create the bodies in the init() function, then move them in the update(delta) function.
Also note that you must "require("utils.lua")"
Add the following in the update() function.
Give that a try! Enjoy!
Note that you create the bodies in the init() function, then move them in the update(delta) function.
Also note that you must "require("utils.lua")"
Add the following in the update() function.
Give that a try and watch a nebula spiral into a black hole. Quite satisfying! Enjoy!
Thanks in advance!
The cool thing is much of the setup is handled by variables that gives you easy control on where to put the system, the radius of the bands from the blackhole center, the density of nebula and the degree of spread, as well as the number of asteroids and their velocity range. Just take a read through, and "it will be obvious to the casual observer..." (as my first C++ instructor loved to say /grin/).
I've also included two GM console buttons to toggle the orbital movement, and (wait for it....) to toggle moving the entire system along a path. Yup -- the whole thing travels. Just a linear path along X axis in this example, but it's easy to find the location in the code where the path is determined and you could change the path to be anything that suits your scenario script.
I hope you find it useful, or at least mildly entertaining, ha.
Happy orbiting! Enjoy!
Drat!
Script was too long to post here! Ok, here's a link to the script file:
https://drive.google.com/open?id=1eMlqXe6NrEKbZcbL5bB81T0AoRQ2reF6
If that doesn't work for some reason in the future, msg me and I'll get you a link.
Looking at a For loop effecting all object but wondering how you would approach it?
My sincere apologies for my absence. I had to go on an unexpected trip a few weeks back and then there was the joyous crush of Christmas. So again, my apologies.
Ref your question regarding the whirlpool effect, yes! Depending on the scope of the space objects you want to have affected by the gravitational pull of the black hole, here's how I would approach it:
-- in the init() function, put everything you want to have affected by the BH into a multi-dimensional array; the first element in the first array is (of course) the second array, then the elements in the second array will be 1) the space object that will spiral, 2) it's angular location of the object to the BH, 3) the angular speed at which the item is spiraling towards the BH, 4) the radial speed at which the item is approaching the the BH
-- in the update() function, you can use a for loop to iterate through the multi-dimensional array (the ipairs function works great here) and make all the updates to the space objects depending on their angular and radial speeds
The whirlpool code example shows how to work through the math decrements to get the space object to spiral into the BH.
If you look in my most previous orbital example ("scenario_xx_blackhold_orbital_debris.lua"), I use several multidimensional arrays. Just in case you need it, here's the Lua reference link: https://www.lua.org/pil/11.2.html
Funny, but I mention in the post above that I was planning to use the whirlpool function to implement a larger environment idea where the BH is leeching off a nearby star. The effect would generally be that the large radius star (20000?) is throwing off nebula which get immediately caught up into the BH gravitational pull and then sucked in! And of course it wouldn't be just a single line of nebula, but more like a "V" coming off the star and then condensing to a thick stream into the BH.
Again, sorry for the break!