Fluid borders

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
Lennartos
Posts: 5
Joined: Wed Oct 07, 2009 2:09 pm

Fluid borders

Post by Lennartos »

Hi

I am doing some preliminary research on our next game.
To that end i am investigating alghrotytms to calculate fluid borders.

Imagine opposing forces (game entities) each with its own radius and force, pushing each other away according to direction and weight of the entity.

please look at the following picture:
Image

The force should be visible as a color around each unit with fluid border between opposing forces (projecting generated texture on map?), Thus showing the force concentrations and friction points.

I have not been able to find any code or other hints on the net, but i remember seeing just this kind of behavior in a game some years ago, where the US was invaded by USSR would fight on us soil, after the cuban crises... something like that

Do any of you have any ideas on how to solve this?
hayate
Posts: 43
Joined: Mon Feb 16, 2009 9:38 pm
Location: Brescia, Italy

Post by hayate »

Maybe something like Bezier Curves can be useful. :D

http://en.wikipedia.org/wiki/B%C3%A9zier_curve
Sorry for my awful english ^_^'
Image
Lennartos
Posts: 5
Joined: Wed Oct 07, 2009 2:09 pm

Post by Lennartos »

Not a bad idea for the border drawing, but that still leaves the actual force calculation...

As i said, i want to have the opposing forces to push each other around, and also to get the friction value of both... (friction meaning losses)
The main application will of course like the picture be combat simulations.

I have thought about it the last couple of days, and the whole idea can be summarized as magnetic forces.

Imaging each of the units above as same polarity mangets.. as more (friendly) magnets assemble the magnetic field around them gets stronger - at places where there is a large space between them, the magnetic force is weaker, and an equal polarity can more softly enter.(an enemy force)

Each magnet can push the others around, but the more resistance is met the slower the progress.

So i have been thinking about how to visualize that, and asked here for help ;)

It can be archived in many ways, as i see it:

large scale games - like starcraft(ground of zergs, that expands),disciples 2 (ground that expands from each town) use some kind of action points.
In disciples 2's case its xx AP for each town - they then try to slowly expand and take over the ground of others where each takeover costs 1 ap, and no range or radius limitations apply... where in starcrafts case its limited to a radius from each building.

This could also be used in this simulation(giving each unit xx amount of AP and fighting it out on a smaller basis), but as each "province" / land area size is one pixel i fear that would not be feasible to calculate on a world scale like planned (think 44.000 * 20.000 pixels and around 2000 units on map)

So is there any way to simulate this bahavior on a larger scale like proposed here.
For example would it be possible to use some kind of ODE or physics engine, and have them act just as opposing forces / magnets, reading out the friction on both...
Or should i look at fluid calculations for help(having them act as drops of oil and water, etc)?


Or am i totally on the wrong track on how to solve this? :(
PI
Posts: 176
Joined: Tue Oct 09, 2007 7:15 pm
Location: Hungary

Post by PI »

Oh my god, what's happening to my home country?!? :D II. World War?
Lennartos
Posts: 5
Joined: Wed Oct 07, 2009 2:09 pm

Post by Lennartos »

Yup..

Im the lead developer on Aarsenal Of Democracy(ww2 simulation), due in december this year.
So im beginning to look for Ideas for the next game / games. :wink:

EDIT: link for game:
http://www.paradoxplaza.com//index.php? ... Itemid=257
Lennartos
Posts: 5
Joined: Wed Oct 07, 2009 2:09 pm

Post by Lennartos »

anyone have any idea on force calculations?
DavidJE13
Posts: 165
Joined: Tue Jan 09, 2007 7:17 pm

Post by DavidJE13 »

people won't be willing to work out the logic for you, but if you have a specific question about how to implement something, that's fine. (i.e. how to re-colour a mesh by position = ok, how to simulate a plane = bad)

on those lines, I can help with the magnet stuff; don't use a physics engine, it'll be bloat. It's a simple calculation;

psudo-code; won't compile but should give you an idea

Code: Select all

for( i = 0; i < units.size; i ++ )
 for( j = i + 1; j < units.size; j ++ ) {
  a = units[ i ], b = units[ j ];
  dx = a.x - b.x;
  dy = a.y - b.y;
  d = sqrt( dx * dx + dy * dy );
  if( d < 50 ) { // Use some distance formula here, and give a maximum range of influence to save computing / achieve better effects
   dx *= 0.05 / d; // Change the 0.5 here (and line below) to change the magnet strength
   dy *= 0.05 / d;
   a.x += dx;
   a.y += dy;
   b.x -= dx;
   b.y -= dy;
  }
 }
This code will make all units repel in a *very* simplistic way, so you'll need to set up some boundaries yourself, and driving forces. To make it more realistic, you can add individual unit strengths, where strong units move faster (replace last 4 lines with:

Code: Select all

   a.x += dx * a.strength;
   a.y += dy * a.strength;
   b.x -= dx * b.strength;
   b.y -= dy * b.strength;
) and maybe some detection of friend/foe.
Lennartos
Posts: 5
Joined: Wed Oct 07, 2009 2:09 pm

Post by Lennartos »

Hi, Sorry for the late reply

Quite busy :roll:

Thanks for the idea - yes that would be a good start to begin simple debugging / testing...

And im not asking anybody to code for me, i am just looking for ideas on how to preoceed...
Post Reply