Author Topic: Starting out  (Read 7654 times)

Jeheace

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 33
Starting out
« 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'?


Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 14
  • Posts: 1,035
Re: Starting out
« Reply #1 on: August 03, 2010, 05:31:11 AM »
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

Jeheace

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 33
Re: Starting out
« Reply #2 on: August 03, 2010, 11:25:32 AM »
Awesome! ^-^ I'll definitely have to test this out!


annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Starting out
« Reply #3 on: August 03, 2010, 09:19:47 PM »
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!

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Starting out
« Reply #4 on: August 03, 2010, 09:26:20 PM »
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:

Code: [Select]
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!
« Last Edit: August 03, 2010, 09:29:53 PM by annikk.exe »

Jeheace

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 33
Re: Starting out
« Reply #5 on: August 04, 2010, 04:49:14 AM »
^-^ 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.

Jeheace

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 33
Re: Starting out
« Reply #6 on: August 04, 2010, 05:42:36 AM »
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)

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Starting out
« Reply #7 on: August 04, 2010, 10:11:26 PM »
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.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Starting out
« Reply #8 on: August 04, 2010, 10:29:06 PM »
Confirmed working.


Change this line:

Code: [Select]
for wrap = 0,9 do

To this:

Code: [Select]
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.
« Last Edit: August 04, 2010, 10:32:36 PM by annikk.exe »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Starting out
« Reply #9 on: August 04, 2010, 10:50:35 PM »
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.


Code: [Select]
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.  :>

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Starting out
« Reply #10 on: August 05, 2010, 02:13:34 AM »
nice stuff here...
good ideas guys.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Starting out
« Reply #11 on: August 05, 2010, 02:16:22 AM »
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... :>

Jeheace

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 33
Re: Starting out
« Reply #12 on: August 05, 2010, 03:56:52 AM »
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...
« Last Edit: August 05, 2010, 04:37:29 AM by Jeheace »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Starting out
« Reply #13 on: August 05, 2010, 04:36:23 AM »
Did you read my other reply?

The one starting "PS, here's something else you might find useful."

Jeheace

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 33
Re: Starting out
« Reply #14 on: August 05, 2010, 04:47:55 AM »
Opps... ^-^ Got so busy trying to catch the roid that I missed that completely!


annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Starting out
« Reply #15 on: August 05, 2010, 07:41:03 AM »
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..

Jeheace

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 33
Re: Starting out
« Reply #16 on: August 05, 2010, 09:31:44 AM »
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..?

Ytaker

  • Tester
  • Seedling
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 33
Re: Starting out
« Reply #17 on: August 05, 2010, 10:37:01 AM »
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.

Farnett

  • Guest
Re: Starting out
« Reply #18 on: August 05, 2010, 11:30:18 AM »
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. 

Jeheace

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 33
Re: Starting out
« Reply #19 on: August 05, 2010, 11:40:58 AM »
And right now, I'm doing some trial and error to find good distance from sun and roid density to create stable orbits.

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 14
  • Posts: 1,035

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Starting out
« Reply #21 on: August 05, 2010, 05:53:55 PM »
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 :>
« Last Edit: August 05, 2010, 05:57:54 PM by annikk.exe »