Author Topic: Gravity Engine Template  (Read 17644 times)

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Gravity Engine Template
« on: May 19, 2010, 07:49:20 AM »
I have prepared a template that should make it easy for other level designers to create levels with the Gravity Engine.

This thing is covered in comments that literally guide you through every step.

Please post in this thread for support.


[edit - removed an unnecessary comment that somehow slipped through, and was mainly me talking to myself...mostly in expletives.. :P]
« Last Edit: May 22, 2010, 08:01:49 PM by annikk.exe »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Gravity Engine Template
« Reply #1 on: May 20, 2010, 12:24:32 AM »
6 downloads already... how are you guys getting on? :>  Let me know if it gives you any trouble!  It would be totally awesome to see other maps made with this thing.

Bonobo

  • Achiever
  • Old Oak
  • ****
  • Thank You
  • -Given: 139
  • -Receive: 12
  • Posts: 670
  • Eufloria: Yes
Re: Gravity Engine Template
« Reply #2 on: May 20, 2010, 05:13:21 AM »
Perhaps they’re still sitting with mouths agape? ;D

w4tc

  • Achiever
  • Shrub
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 170
Re: Gravity Engine Template
« Reply #3 on: June 21, 2010, 09:00:01 AM »
I would like to learn more about it
You can explain it step by step?
How i must begin ( and othere xD )

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Gravity Engine Template
« Reply #4 on: June 21, 2010, 05:04:03 PM »
The code is heavily commented, telling you what each part does and how to modify it.  :>
If there's any aspect within that which is giving you trouble, let me know which part and I shall explain.

Or did you mean you want to know how the engine itself works?  I didn't comment that part very much, I kinda wanted to reduce it to a nice small block :>

w4tc

  • Achiever
  • Shrub
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 170
Re: Gravity Engine Template
« Reply #5 on: June 21, 2010, 07:42:18 PM »
a bit of both xD
but it will be cool if like it as "the Guide to making levels for Absolute Beginners" xD
stap by stap build up with Image or somthing to beter understand

but i will try it in the night

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Gravity Engine Template
« Reply #6 on: June 22, 2010, 03:19:43 AM »
It's basically just the law of gravity and various newton laws, from physics, which are represented in terms of code.

I commented the code heavily instead of doing a picture guide like I did for the beginners guide.  If anything within the comments is not clear, please let me know.  Have you actually read through the template yet? :>

w4tc

  • Achiever
  • Shrub
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 170
Re: Gravity Engine Template
« Reply #7 on: June 22, 2010, 05:33:12 AM »
Yes, but there are difficult things
that I do not understand it so well :$ and with those terms ect

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Gravity Engine Template
« Reply #8 on: June 22, 2010, 04:08:03 PM »
Can you be specific about what you're having difficulty with?  I am very busy moving house right now and don't have time to write out a beginner's guide to gravity.  It's anyway not aimed at beginners.

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Gravity Engine Template
« Reply #9 on: July 03, 2010, 11:27:16 PM »
hello!
been reading through this code template and because i am who i am, i find myself firstly thanking you for such kind work and then asking a lot of 'why' questions.
eg, you write at the top, 'these shouls always be kept at zero', or such and such, and i find myself thinking, 'why must it be kept at 0'?

im sure you recall my many questions what seems like ages ago now, but im the kind of person that needs to know exactly why something needs to be a certain, not out of trying to prove someone incorrect, but so i can understand the underlying reason for why it is the way it is, from there i can understand so much better.

having said all that, i havent gone through it all in depth and im sure it's all groovy, but 'why' is very important in my comprehension of something. just thouight id share that as food for thought, etc.

lol


aws

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Gravity Engine Template
« Reply #10 on: July 04, 2010, 10:29:00 PM »
Well, I suppose you don't _have_ to keep them at zero... but the gravity engine sort of assumes they will be zero at the start, and in many cases the reason why they are 0 is just to make it easier to plan out the level.

Here's an example.
Suppose you set an initial acceleration which wasn't zero.  On the first game cycle, the acceleration would be added to the momentum, and then set to zero - ready for the 2nd game cycle.
So momentumx = 5 and accelerationx = 5 would mean on the first game cycle, momentumx would become 10 and accelerationx would go back to 0.
It would achieve the same result and be easier (for you) to just say momentumx = 10 and leave accelerationx on 0.

So I recommend leaving accelerationx at 0 in the initial conditions because it's just easier than having two different numbers to pay attention to.  :>


Note that changing these "should-be-zero" values is untested, and might provide unexpected results.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Gravity Engine Template
« Reply #11 on: July 09, 2010, 08:38:33 PM »
Right, I got some free time to spare on this now.  Anyone working on a gravity level and needs some help? :>  AWS (or anyone else) had some more questions about it?

I'm still not going to do a "beginners guide", because dealing with gravity is pretty advanced and there is some required knowledge, but I think for people who have made a few maps now and are comfortable working in LUA, it should be pretty easy to figure things out from the template itself, and I will be here if you have any questions about it.  :>

w4tc

  • Achiever
  • Shrub
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 170
Re: Gravity Engine Template
« Reply #12 on: July 10, 2010, 08:43:04 AM »
Thx Annikk for helping
I'm beginning to understand it a bit

so what I am now trying is for a second asteroid to place to another
and that does not work hmmm i dont see why?

a othere question, when must we change in the Gravity Engine
is it here that nothing to do with the number of asteroids that you want to put a Gravity?

(click to show/hide)

Edit : before I forget, can i put one Gravity asteroid in a levelmap? or must it be two?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Gravity Engine Template
« Reply #13 on: July 10, 2010, 11:30:54 PM »
Code: [Select]
-- Asteroid 1 - A moving asteroid
-- gravity variables
roid = 1
AccelerationX[roid] = 10
AccelerationY[roid] = 0
MomentumX[roid] = 0
MomentumY[roid] = 6.5
density[roid] = 0.8
CoordX[roid] = 6000
CoordY[roid] = 0
roidradius[roid] = 350

-- Creation
a = AddAsteroidWithAttribs(CoordX[roid],CoordY[roid],0.1,1,1)
a.Owner = 2
a.TreeCap = 2
a:SetRadius(roidradius[roid])
a:Reveal(1)
a.Moveable = False

-- Asteroid 3 - A moving asteroid
-- gravity variables
roid = 4
AccelerationX[roid] = 0
AccelerationY[roid] = 0
MomentumX[roid] = 0
MomentumY[roid] = 6.5
density[roid] = 0.8
CoordX[roid] = 8000
CoordY[roid] = -10
roidradius[roid] = 300

-- Creation
a = AddAsteroidWithAttribs(CoordX[roid],CoordY[roid],0.1,1,1)
a.Owner = 2
a.TreeCap = 2
a:SetRadius(roidradius[roid])
a:Reveal(1)
a.Moveable = False


This is incorrect.  You can't have roid 4 after roid 1.  You have to do it in order.

Change roid = 4 to roid = 2
Then change any subsequent asteroids so they are in order too.  It should go 0, 1, 2, 3, 4, 5... etc

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Gravity Engine Template
« Reply #14 on: July 10, 2010, 11:40:16 PM »
Quote
Edit : before I forget, can i put one Gravity asteroid in a levelmap? or must it be two?

There are three different types of asteroids in the gravity engine.


Asteroids that remain stationary, but have a gravity well which can affect other asteroids that DO move....
Asteroids that move about, and are affected by gravity.
...and asteroids that do not move, and do not produce a gravity well.


You have to enter these asteroids in each section, in the correct order.

For example:


Type 1

roid = 0
roid = 1
roid = 2

Type 2

roid = 3
roid = 4
roid = 5

Type 3

roid = 6
roid = 7
roid = 8




Obviously you would need to put the gravity variables and the creation code for each asteroid too, below each "roid ="




You could put 1 asteroid of type 2 in if you like.  If there are no other asteroids of type 1 or 2 in the level, your gravity asteroid won't move, though.

Jeheace

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 33
Re: Gravity Engine Template
« Reply #15 on: August 05, 2010, 05:12:49 AM »
Anikk.exe, Would it be ok with you if I tampered with your gravity engine? I want to use it as is, but I also want to toss in one or two roids with reverse gravity into the mix... that'll throw some people off ^-^

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Gravity Engine Template
« Reply #16 on: August 05, 2010, 05:26:06 AM »
Why tamper with the engine? Just give the asteroid a negative density, shouldn't that work?

Jeheace

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 33
Re: Gravity Engine Template
« Reply #17 on: August 05, 2010, 05:47:20 AM »
Testing that right now, but I'm thinking that due to the math in the GE it may not... a neg times a neg is a posi

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Gravity Engine Template
« Reply #18 on: August 05, 2010, 05:51:34 AM »
Ah, yeah...

Jeheace

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 33
Re: Gravity Engine Template
« Reply #19 on: August 05, 2010, 06:14:31 AM »
Ok, Think I got it... testing now, and so far so good...

Changed line:
Fgx = (G * ((roidradius * roidradius) * math.pi * density) * ((roidradius[j] * roidradius[j]) * math.pi * density[j])) / ((CoordX[j] - CoordX)^2 + (CoordY[j] - CoordY)^2)
               Fgy = (G * ((roidradius * roidradius) * math.pi * density) * ((roidradius[j] * roidradius[j]) * math.pi * density[j])) / ((CoordX[j] - CoordX)^2 + (CoordY[j] - CoordY)^2)

To:
Fgx = (G * ((roidradius * roidradius) * math.pi * density) * ((roidradius[j] * roidradius[j]) * math.pi * -density[j])) / ((CoordX[j] - CoordX)^2 + (CoordY[j] - CoordY)^2)
               Fgy = (G * ((roidradius * roidradius) * math.pi * density) * ((roidradius[j] * roidradius[j]) * math.pi * -density[j])) / ((CoordX[j] - CoordX)^2 + (CoordY[j] - CoordY)^2)


LOL! YES! IT WORKED! ^-^
« Last Edit: August 05, 2010, 06:19:56 AM by Jeheace »

Jeheace

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 33
Re: Gravity Engine Template
« Reply #20 on: August 05, 2010, 06:26:21 AM »
The moving roid now does all it can to avoid the sun...

BTW, THIS IS AN EDITED VERSION OF annikk.exe's GRAVITY ENGINE PLUS SCREEN WRAP.

Now, to make the two work together, I need to be able to manually add roids to the respective rosters.
« Last Edit: August 05, 2010, 06:32:39 AM by Jeheace »

w4tc

  • Achiever
  • Shrub
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 170
Re: Gravity Engine Template
« Reply #21 on: August 05, 2010, 06:38:32 AM »
wow xD lool if you long enough wait you have a very beautiful bug :o

Jeheace

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 33
Re: Gravity Engine Template
« Reply #22 on: August 05, 2010, 06:51:11 AM »
Yeah, and I didn't even have to change what I did... all I really needed to change was G = 0.1 to G = -0.1 ^-^

Perhaps is should try with a lower density... or lower radius of g field

The 'Dancing fire fly'

That what I'll name that particular bug ^-^
« Last Edit: August 05, 2010, 06:54:50 AM by Jeheace »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Gravity Engine Template
« Reply #23 on: August 05, 2010, 07:38:40 AM »
Quote
Anikk.exe, Would it be ok with you if I tampered with your gravity engine?


Of course it's ok :>

Playing with gravity rules.  :>  I have had so much fun messing around with it, and I also have created things like asteroids that "blow" instead of "suck".. :>
There is an absolute ton of cool stuff you can do with it, and it seems like you've got to grips with how to mess around with it.... enjoy.. :>

Jeheace

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 33
Re: Gravity Engine Template
« Reply #24 on: August 05, 2010, 07:51:01 AM »
^-^ Thanks!

Well... I can get gravity to work, and I can reverse it (several different way), but I can't get both at running at the same time...
« Last Edit: August 05, 2010, 10:06:55 AM by Jeheace »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Gravity Engine Template
« Reply #25 on: August 05, 2010, 06:15:42 PM »
You could make a new divider.  Then when running gravity calculations, you could make some of the rows in the matrix blow instead of suck by changing the value of G to be G * -1.

So instead of for i = 0, roidnumber do you would have for i = 0, (roidnumber - 2) do and then later on another one, for i = (roidnumber -1), roidnumber do followed by a G = G * -1.

That's how I'd do it, anyway.

dragoonreas

  • Seedling
  • **
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 37
  • Eufloria: Yes
Re: Gravity Engine Template
« Reply #26 on: August 08, 2010, 11:23:09 PM »
I was originally just going to have a quick fiddle around with the gravity template, but then I kept on thinking of more stuff to do to it to make it more dynamic, a bit more flexible, etc... and now I've ended up with this near total re-write. :o

The two major changes I made functionality wise are:
  • Being able to change an asteroids gravity behaviour at any time. This also means you don't have to enter asteroids in groups based on their gravity behaviour anymore.
  • Having 6 gravity behaviours to choose from. The behaviours are combinations of asteroids that are (1) Static or (2) Moving, and have (A) Normal Gravity, (B) Anti-Gravity or (C) No Gravity.

I also included an asteroid wrapping and speed management system, both of which were based off the ones in AntiGTest07 by Jeheace.

Although I haven't documented the internals of the engine (the big, +400 line block at the bottom), I have documented how to use it. :)

Jeheace

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 33
Re: Gravity Engine Template
« Reply #27 on: August 09, 2010, 04:55:10 AM »
Both the wrapping and speed management were by Annikk... basically all I added was some ideas! ^-^

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Gravity Engine Template
« Reply #28 on: May 15, 2011, 07:31:28 AM »
Yay, thanks alot annikk... Made a little gravity simulator :D

Click to add new dots/entities... See how many moons you can have, and to get some big dots you can manually into the console and write "Mass[Entities] = 'any number wanted here, 100 is an average mass!'". The more mass, the more gravity :)

Update: Added a slider for mass changing when you select an object, to deselect it, click the gray button in the bottom of the screen :)

Edit: I might eventually make a "big" game with all this components I'm making :D
« Last Edit: May 16, 2011, 04:13:49 AM by Aino »