Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411629 Posts in 69392 Topics- by 58447 Members - Latest Member: sinsofsven

May 11, 2024, 02:13:43 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Pseudo physics in a grid-based environment
Pages: [1]
Print
Author Topic: Pseudo physics in a grid-based environment  (Read 1536 times)
Kekskiller
Guest
« on: January 09, 2010, 09:24:27 AM »

Hello fellows,

I'm looking for some alternatives to typical physics calculations for a grid-based game. For a game where you only have a grid and no exact floating point position between the grid squares (like in a roguelike). Every object on this grid can only move by placing it + x/y/z from the original position. I just need a simple gravity physics that works fine with integer grid positons.

At first I tried a more realistic version by implementing a frequency-based system (x steps every second, for each axis a single timer). It's unpredictable, not very stable and needs a lot more workarounds. Since I'm seemingly the only person on the internet who does something like this I don't know where to get help.

Anyelse an idea? I'm somehow stuck. Again.
Logged
Theotherguy
Level 1
*



View Profile
« Reply #1 on: January 09, 2010, 10:22:48 AM »

Hello fellows,

I'm looking for some alternatives to typical physics calculations for a grid-based game. For a game where you only have a grid and no exact floating point position between the grid squares (like in a roguelike). Every object on this grid can only move by placing it + x/y/z from the original position. I just need a simple gravity physics that works fine with integer grid positons.

At first I tried a more realistic version by implementing a frequency-based system (x steps every second, for each axis a single timer). It's unpredictable, not very stable and needs a lot more workarounds. Since I'm seemingly the only person on the internet who does something like this I don't know where to get help.

Anyelse an idea? I'm somehow stuck. Again.

What exactly are you trying to do? What sort of precision do you want? How accurately do you want to model physics?

Here's the thing, any physics implementation which works for floating point vectors will work for integer vectors. It would be a trivial task to implement a basic floating point physics engine and then round off the vectors to your grid space.

But if you must make it fully discrete, just assign every object in the world a 3-dimensional vector corresponding to its position, velocity, and the sum of forces acting on it as integers. This is basically exactly what you were doing when you did "for each axis a single timer."

If you don't want things to behave realistically, you can just give each object a z speed and increase that constantly if it is not touching the ground.
Logged

Kekskiller
Guest
« Reply #2 on: January 09, 2010, 10:26:56 AM »

Here's the thing, any physics implementation which works for floating point vectors will work for integer vectors. It would be a trivial task to implement a basic floating point physics engine and then round off the vectors to your grid space.

And that's what I want to avoid. I'm for looking that doesn't use the typical floating point calculations. Accuracy isn't that important.
Logged
Theotherguy
Level 1
*



View Profile
« Reply #3 on: January 09, 2010, 10:31:49 AM »

Here's the thing, any physics implementation which works for floating point vectors will work for integer vectors. It would be a trivial task to implement a basic floating point physics engine and then round off the vectors to your grid space.

And that's what I want to avoid. I'm for looking that doesn't use the typical floating point calculations. Accuracy isn't that important.

Then my suggestion is still to do it simply by assigning 3-dimensional integer vectors for position, velocity, and forces to each of your game objects.

It's fairly simple really,

Code:
pseudocode
/* Some Vector class*/
Class Vector3I
{
    int X;
    int Y;
    int Z;


    add(Vector3I other)
    {
        X += other.X;
        Y += other.Y;
        Z += other.Z;
    }

    scale(float scalar)
    {
      X = (int)(X*scalar);
      Y = (int)(Y*scalar);  
      Z = (int)(Z*scalar);
    }
}

/*For each of your game objects*/
class PhysicsObject
{
   Vector3I position;
   Vector3I velocity;
   Vector3I impulse;

   addForce(Vector3I force)
   {
     impulse.add(force);
   }

   update(float seconds)
   {
        position.add(velocity);
        impulse.scale(seconds);
        velocity.add(impulse);
        impulse.scale(0);
   }
}

/*A constant*/
Vector3I gravityForce = new Vector3I(0,0,-10);

/* In your physics engine*/
foreach(PhysicsObject object in objects)
{
   object.addForce(gravityForce);
   object.update(changeinTime);
   

}

« Last Edit: January 09, 2010, 10:41:19 AM by Theotherguy » Logged

raigan
Level 5
*****


View Profile
« Reply #4 on: January 09, 2010, 11:03:12 AM »

This might be of interest (I don't think it's ever been completed though): http://playtechs.blogspot.com/2009/03/square-based-turn-based-rigid-body.html

I think you probably don't really need a "simulation", the movement of objects might be better of being modeled using logical statements about how they should behave in each particular case rather than something more akin to a physics simulation.

For instance, this isometric room example: http://bannalia.blogspot.com/2008/02/isometric-room.html

If you look at the source code you'll see that object movement is described procedurally, for instance (AFAICR) gravity is simply a case of moving objects downward if there isn't anything below them, and pushing whatever's below downward otherwise.

The way that pushing/simulation works in that room is actually pretty smart, it can handle stacks/etc. without any actual "physics".
   
Logged
Alex May
...is probably drunk right now.
Level 10
*


hen hao wan


View Profile WWW
« Reply #5 on: January 09, 2010, 11:11:02 AM »

have an internal floating point representation for the position and cast it to integer for the real position. if the integer changed, your character has moved.
Logged

nikki
Level 10
*****


View Profile
« Reply #6 on: January 11, 2010, 04:03:31 AM »

i would cast it too , why lose all that groovy data behind the comma , you never know when it comes in handy  Ninja
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic