Finding position with linear damping

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Finding position with linear damping

Postby deadvirus » Thu Aug 06, 2009 7:05 pm

Hello,
I'm doing a client/server network game, and I need to do some client-side prediction. I want Newton to run only on the server. I use a hight linear damping on my players.
The problem is on the client I'm trying to find their positions using:
mVelocity += mAcceleration * timeSinceLastFrame;
mPosition += mVelocity * timeSinceLastFrame;

The problem is that this does not take damping in the mix! So my velocity will be greater than it should be... How can I put damping into it?


Thank you.
deadvirus
 
Posts: 5
Joined: Thu Aug 06, 2009 6:57 pm

Re: Finding position with linear damping

Postby Julio Jerez » Thu Aug 06, 2009 7:18 pm

you cannot really do such naive prediction because if the player something the velocity isl changed by the collison system.

The what I can think off is by using two worlds, and move one ahead, then reset or resynk.
but that will advance all bodies not just one.

basically you have one world teh you move forword,

day worlk1 is the working world world 2 in the backup, teh algorith woudl be liek this

//sync world1 to world2 world2
for each body in world1,
GetVelocity and Position from each Body, and set into the each Body in world2

// suncronize boteh world
invalidteCache(world1)
invalidteCache(world2)

advnace world1 by the amount of prediction steps
whiel (number of prediction steps)
NetwonUpadte (world1))

//Ready the prediction, and do you AI stimation.
do you prediction code for all bodies that you need at once.

continues advancing the game logic in world2.

do the same each time you need to predict anything in world2 by suncronizing teh world and ancacing world1
the mopre bodies you need to predict at once the more efficent, ideallyy you do it once for all bodies.
Basically orld1 is a probe world.
you can save the Body pointer of each body in world2 as the user data of world1 and skip the transform call back
every thong you do in world one you also do in world tow, like adding nodies anr or joint,

I do not know if this is clear, I hope you get the idea.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Finding position with linear damping

Postby Julio Jerez » Thu Aug 06, 2009 7:49 pm

On the client size is very much the same.
You can have a small world with the bodies that are in some sliding window around the player
Then you run that world to predict what there server is doing and I have the = benefic the prediction code will be more correct since it will also move the bodies in the sliding box the same way the server does.

The down size if teh you may need to keep track of what is in eth small world in the client
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Finding position with linear damping

Postby deadvirus » Fri Aug 07, 2009 4:06 pm

Thank you Julio, I think I get the idea...
The problem is that the date to present the prototype is to close, and I don't have time to implement Newton physics on the players, because it will bring some problems along with it.
So I need something simpler, less accurate and safe of course, but simpler. Like doing some simple interpolation... For the prototype I only need this to work on LAN, so I don't need something "bulletproof"...
In the future I'll will use Newton physics on the player, but for now, I can't :cry:

Thanks.
deadvirus
 
Posts: 5
Joined: Thu Aug 06, 2009 6:57 pm

Re: Finding position with linear damping

Postby Julio Jerez » Fri Aug 07, 2009 5:03 pm

well you can do a piecewise integration loop.
if you have and damp k and the velocity is V
then you can do a integrate V and make a look up table
say you divided teh tiem inervale into N steps, teh table will be like this

Code: Select all
for (i = 0; i < N ; i ++)
{
     v = v - k * v;
     p[i] = v * t  - k * v * dt/n;
}
now have a table of position, in each interplated frame you get thet interpolated position from the table.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest