Euflorium: The Eufloria Community
Eufloria => Eufloria Classic => Eufloria Classic Mods => Topic started by: Jeheace on August 03, 2010, 04:42:28 AM
-
I'm new to this, and I feel, sadly, that I may become a cut and paste map builder... but I plan on using gravity in most of my maps...
Now comes the question/idea part...
I'm planning a map with several free floating roids that interact with each other slightly with their gravity...
If one of my little rocks strays too far, I don't want the map to keep expanding endlessly... is there already a function for 'room wrap'...? in other words, is there a way to say 'x is the max room size, if roidA is beyond room boundaries, move it to the other side of the room with same speed and movement'?
-
Yes, you should be able to do that pretty easily...
let's see
worldsize = 10000
numAsteroids = GetNumAsteroids()
for i = 0,numAsteroids do
asteroid = GetAsteroid(i)
if asteroid.Position.X < -worldsize then asteroid.MoveBy(worldsize + worldsize, 0) end
if asteroid.Position.X > worldsize then asteroid.MoveBy(-(worldsize + worldsize), 0) end
if asteroid.Position.Y < -worldsize then asteroid.MoveBy(0,worldsize + worldsize) end
if asteroid.Position.Y > worldsize then asteroid.MoveBy(0,-(worldsize + worldsize)) end
end
I'd better document the Position thing... :o
-
Awesome! ^-^ I'll definitely have to test this out!
-
heh sweet. Wish I'd thought of that. :>
I ah.. might steal that functionality for the big bang map.. if that's cool? :> I will honestly get round to making this thing someday soon!
-
By the way, if you want to implement this with the gravity engine, it will just screenwrap the asteroids for you automatically... all you'd need to do is change the CoordX and CoordY arrays. In fact, it will produce very unpredictable behaviour if you don't do it this way.
First let me explain about the way the gravity engine treats asteroids coordinates.
Asteroid 0's X and Y coordinates are stored in CoordX[0] and CoordY[0].
For Asteroid 1, it's CoordX[1] and CoordY[1], and so on.
So if you had ten asteroids in the level, you'd need to do a for loop, something like this:
for wrap = 0,9 do
if CoordX[wrap] > 10000 then
CoordX[wrap] = -10000
end
if CoordY[wrap] > 10000 then
CoordY[wrap] = -10000
end
if CoordX[wrap] < -10000 then
CoordX[wrap] = 10000
end
if CoordY[wrap] < -10000 then
CoordY[wrap] = 10000
end
end
Chuck that code into the Gravity Engine template below this line:
while GameRunning() do
Should work good :> Feel free to change the bounds of the level from 10000 if you so desire...
By the way, it's supremely awesome that you're having a go at this :> I'm really stoked to see what you come up with!
-
^-^ That'd be awesome! Any thing I come up with, if ya'll can get it working, ya'll can use it.
I'm more of a concepts person anyway.
-
Dropped into the Gravity Template as suggested...
So far, only one issue emerged...
All planetary movement has ceased o.O
Will see if there's any adjustment that I can figure out to fix it... (probably not)
-
Try pressing tilde to bring up the console view. Is there any error message?
Also, did you modify the code so that it references the ACTUAL number of asteroids in the level? Remember that example I gave was for 10 asteroids, but in the template I think there are only 3 by default !
If you've got wrap code for 10, but only 3 roids, it would stop running the engine and produce an error in the console window. It sounds like this is what has happened.
Testing it now myself, will post back in a sec.
-
Confirmed working.
Change this line:
for wrap = 0,9 do
To this:
for wrap = 0,roidnumber do
That way it automatically picks up how many asteroids are in the level. I have tested the wrapping functionality too, by changing the moving asteroid in the template to have a larger initial momentum so that it flies off the bottom of the screen. It then reappears at the top, still travelling south.
-
PS, here's something else you might find useful.
This code will reign in any asteroids that are travelling at warp speed, and make them slow down gradually to a more playable pace.
for slow = 0,roidnumber do
if MomentumX[slow] > 25 or MomentumX[slow] < -25 then
MomentumX[slow] = MomentumX[slow] * 0.99
end
if MomentumY[slow] > 25 or MomentumY[slow] < -25 then
MomentumY[slow] = MomentumY[slow] * 0.99
end
end
Just put it below the wrap code. :>
-
nice stuff here...
good ideas guys.
-
I ran a Eufloria gravity simulation that resulted from these changes for 4 hours at work today, using a total of 50 asteroids which were assigned random attributes for coordinates, initial momentum, radius and density.
It's pretty awesome. By the way, the Infected AI would be able to conquer a galaxy like this in an extremely efficient manner. The AI in the Big Bang is going to be pretty deadly... :P
Have a look for yourself... :>
-
Yes, that seemed to be the problem! ^-^ It was looking for asteroids that didn't exist... I like that new line... It'll take into account any new roids that decide to magically spawn (devious grin)
WOW! I set the momentum to 25 just to get it moving... after several near passes to the singularity (large gravity well roid) it pass ALMOST right through the gravity center... at which point it made a sharp u-turn and shot off with a really a nice velocity... ^-^
Added some seedlings, then when the moving roid reach top speed, tried to capture it... very tough to do... do you guys think a speed cap is needed?
Perhaps a click and drag box for selecting moving roids... that way you can 'catch' it if it's too difficult to click on...
-
Did you read my other reply?
The one starting "PS, here's something else you might find useful."
-
Opps... ^-^ Got so busy trying to catch the roid that I missed that completely!
-
The functionality that I _really_ want to code is asteroids bouncing off one another, like snooker balls.
Will need to do some research and think about that one a lot. Not sure offhand how I would express that mathematically. I will have to do this for Big Bang, though... my mind is working on it :> Albeit part-time, for now..
-
You need collision detections! ^-^
What happens if the roid i JUST clicked to send my seedlings to sudden vanishes..?
Should they seek the nearest roid, or return to roid of origin..?
-
You need collision detections! ^-^
What happens if the roid i JUST clicked to send my seedlings to sudden vanishes..?
Should they seek the nearest roid, or return to roid of origin..?
Or die in the cold and harsh environment which is space.
-
The functionality that I _really_ want to code is asteroids bouncing off one another, like snooker balls.
Will need to do some research and think about that one a lot. Not sure offhand how I would express that mathematically. I will have to do this for Big Bang, though... my mind is working on it :> Albeit part-time, for now..
That's fairly simple. All you need is the vector between the two objects and the momentum vectors of each asteroid, both of which I believe are already being tracked in your gravity engine. Simply check if the length of the vector between two asteroids is less than the sum of their radii and if so then you have a collision. After that you have two choices, an elastic or an inelastic collision. For an inelastic collision the two asteroids merge (with the smaller one loosing out presumably) and their momentum vectors are added together to get the new momentum vector. For an elastic collision the two asteroids bounce off like billiard balls; you then use the momentum vectors to calculate the angle at which they 'bounce' off of each other.
-
And right now, I'm doing some trial and error to find good distance from sun and roid density to create stable orbits.
-
http://www.gamasutra.com/view/feature/3015/pool_hall_lessons_fast_accurate_.php
-
Collision detection is _very_ simple.
Accurate collision detection, not relying on the 60fps offered by lua, is harder.
(ie, "last frame i had not collided, this frame i am 30 units overlapping. at what point did I go from 0 units to 1 unit overlap? What would the other values have been at that point? These are the variables that must be used for an accurate bounce calculation)
Even harder is calculating the angles they bounce off at.
Thanks for the link Alex, will read up on it :>