Manually update physics

Hi all,



like topic’s title says, I need to update the physics manually only for a specified physics rigid body leaving the entire physics space unaltered.



I saw that there is the update method of CharacterControl class but the javadoc says that this should not be called from user code.

So there is another way to do what i need?



Thanx a lot :slight_smile:

Nope, you also don’t want to do that, any objects that do not move are not computed anyway.

Mmmm… Ok



My problem is that I have to do a manual state update due to client side prediction.

In fact when the server sends the updates of the local player i need to recalculate the inputs from that state to the actual state.



[java]

currentState;

inputList;

while(inputList is not empty) {

serverState = updateState(serverState, nextInput) ;

}



currentState = serverState;

[/java]



In my physics simulation the states are timestamps of the RigidBody that maps the player in the server environment

so i thought the updateState should by a manual call to the CharacterControl.update() method…



Can i do this in another way?

Thanx a lot

Since bullet is deterministic it should run synchronized in theory, so you only need to set the actual changes (like user-applied forces) and then the current velocities at an interval so they run in sync on client and server. MonkeyZone has this implemented, including a simple lag compensation.

If i compute the forces on the client by user input, i have however to sent those to the server, and as i said i need to do some kind of client side prediction.



And again when the game state arrives from server i need to correct the local player starting from this state and reapplying all the inputs stored.



But if i can’t do this how can i implement client side prediction? I’ve just done all the multiplayer system but without collisions and physics.

There is a way to maintain this architecture just adding the physics?



And if there isn’t, can you tell me how to sync a physics state leaving the system server driven?



I’ve done all the lag compensation stuff yet



Thanx for the help

As said, MonkeyZone has this laid out.

Ok, i’ve seen how MonkeyZone does waht you said.



But for what i’ve seen, and correct me if i’m in wrong, monkeyzone does not implement a concrete client side prediction like the way it is meant to be. MZ simply apply data when the server sends the update message. In fact the ManualCharacterControl apply instantly user input and at the same time it sends those ti the server that recalculate the movement and create the update message.



Sorry me if i’m wrong but IMHO it is not a client side prediction mechanism like Q3 has. And moreover this architecture (just as i said IMHO) cannot work in a WAN environment because all the transmissions are made through TCP and i’ve not found any kind of entity interpolation. MZ works very well in a LAN but I’m not sure that it can be played over the Internet.



If i’m wrong can you tell me the class where for example is done the client local player correction through the reapplication of the input on the server-past-correct-state?



Question:

  1. Is there a way to run the entire physics simulation manually?
  2. How can i implement something like this using bulletAppState?



    Client:

    Sample user input and calculate forces to apply to the character rigid body.

    Store and apply those forces locally and send it to the server.



    Server:

    Compute the new game state with user forces and sends a updateMessage



    Client:

    When update message arrives get the local player update and search for a state - forces record with the same time stored in the update state from server.

    Starting from that state, recalculate the new correct state applying all stored forces predicting in this way a more correct position.



    Thanx a lot :slight_smile:

For interpolation you ramp up the tpf for the physics space stepping as outlined in the MonkeyZone comments, as you say the input is only relayed over the server, applying it locally would basically mean delaying local applying and maybe moving the commands sent to the server back in time a bit.

Yes this is a correct approach. But i’m not sure that it can work as well as a real client side prediciton approach.



What i mean is that if the input is simply delayed, there is no difference in applying the updates of the server. In fact client side prediction usefulness is to instantly compute the player input that will be corrected by the server. Delaying inputs is equivalent to applying it when the server update comes.



Am i wrong?

Yes thats correct. You can bend time in both directions as I indicated though, check the valve documents.

Sorry but i didn’t understood. What is the usefulness of bending time in both directions?

The objective of prediction is to instantly applying user input. Delaying it, in every way you do it, is the opposite of what is the prediction objective.



Please, leaving MZ apart for a while, can you teach me how can be implemented an equivalent Q3 system with JM3 and bullet physics?

Thanx :slight_smile:

Pulling back in time, the data you send. Like you have a server-client delay of 20ms then you apply it after 10ms and report the action time as 20ms-10ms=10ms

Edit: and no, I will not play your personal teacher, i wrote MonkeyZone and made it publically available. Also do read the valve documents.

Ok, i’ve got it but i don’t want to do this way.

What i need is to implement client side prediction but if i can’t control the physics i’m not in grade to do this.



Can you answer my previous questions please?


Question:
1) Is there a way to run the entire physics simulation manually?
2) How can i implement something like this using bulletAppState?

Client:
Sample user input and calculate forces to apply to the character rigid body.
Store and apply those forces locally and send it to the server.

Server:
Compute the new game state with user forces and sends a updateMessage

Client:
When update message arrives get the local player update and search for a state – forces record with the same time stored in the update state from server.
Starting from that state, recalculate the new correct state applying all stored forces predicting in this way a more correct position.


Thanx

If you want to run the entire physics manually, you don’t need physics.



But I think you want to adjust the client side physics. You can do that by implementing a PhysicsTickListener and using the PhysicsRigidBody.setPhysics*() methods (RigidBodyControl) to “chase” the values from the server. That would be my naive approach.

I need to update the entire physics manually but i don’t want to write the physics system by myself.



As i said i need to do this due to my prediction system that stores player inputs and compute the correction of it’s position starting from the server sent update and applying the intire list of inputs.



What i need is something like:



[java]

CharacterControl.setPhysicsLocation(stateSentByServer.getPhysicsLocation);

While(!inputList.isEmpty()) {

CharacterControl.setForce(input.getForce);

CharacterControl.update(input.getDeltaTime);

}

[/java]



But i don’t know how to do this

You can do it as I posted here (second listing). In the current version it looks like this:

[java]

private ActionListener actionListener = new ActionListener()

{

public void onAction(String name, boolean keyPressed, float tpf)

{

if (running)

{

if (name.equals(“minusX”))

{

minusX = keyPressed;

}

else if (name.equals(“plusX”))

{

plusX = keyPressed;

}

else if (name.equals(“minusZ”))

{

minusZ = keyPressed;

}

else if (name.equals(“plusZ”))

{

plusZ = keyPressed;

}

else if (name.equals(“menu”) && keyPressed)

{

showMenu();

}

}

}

};



private void handleInput(float f)

{

float val = f * inputSensivity;

boolean update = false;



if (minusX && (rotX > -maxTilt))

{

rotX -= val;

update = true;

}



if (plusX && (rotX < maxTilt))

{

rotX += val;

update = true;

}



if (minusZ && (rotZ > -maxTilt))

{

rotZ -= val;

update = true;

}



if (plusZ && (rotZ < maxTilt))

{

rotZ += val;

update = true;

}



if (update)

{

rotAxisX.fromAngleAxis(rotX, Vector3f.UNIT_X);

rotAxisZ.fromAngleAxis(rotZ, Vector3f.UNIT_Z);

rotWorld.set(rotAxisX.mult(rotAxisZ));



// rotation around origin

floor_phy.setPhysicsRotation(rotWorld);

naby_phy.setPhysicsRotation(rotWorld);



// rotation around ceilPos

Transform t = new Transform(ceilPos, rotWorld);

ceil_phy.setPhysicsLocation(t.getTranslation());

ceil_phy.setPhysicsRotation(t.getRotation());

}

}



public void prePhysicsTick(PhysicsSpace ps, float f)

{

handleInput(f);

// handleInputWithInertia(f);

}

[/java]

OMG!!!

That’s what i was looking for!!! Thanx a lot!!! :smiley:



Only one dubt:

In this way the character risks to be in a solid object when the thick runs because when i update the state i can’t rely on bullet for collision detection. Right?



So in this case, maybe the character risks to be lauched away…



Edit:

i have realized that maybe this way can not be usefull to be because in this manner i have to calculate the next physics state manually…

Is far as I understood, the same simulation runs on the server (but with input from all clients). You just correct the simulation on the client by a small amount each tick. That’s what I meant with “chasing”. You feed the server broadcasted values into a chase function which computes a smooth correction. Setting the server values as soon as they arrive would make your objects “warp”. But you want to be a “smooth operator”, don’t you? :smiley:



Edit: Linear Filters – Animating Objects in a Flexible and Pleasing Way



Again, this is a naive approach. I suppose there are many papers out there which describe how to do it really smart.

“I don’t want to do it like you say, I want you to explain it to me the way I want to do it” - lol xD Look at the MonkeyZone code and read the documents from valve, whats so hard about that? Then you can maybe pose questions that are not so general that one doesn’t know where to start…

@normen

What you don’t understand of what I say?

If you don’t know how to help me, please, leave other this issue and simply don’t reply my posts.



As you always has done, you tell me to read the valve documentation. I’ve done many research and read many other documents. I suggest you to read this blog to understand what i am searching for.



i’ve tought that your MonkeyZone project does not do what i want. I say this simply because MZ can’t be played in a WAN environment. Im i wrong?

I think not :x



So as is sayd if you don’t know how to help me DON’T POST IN THIS TOPIC. THANKS!!!



@survivor

Thanks for your post. This PDF looks really interesting and i’ll read this ASAP.

@normen → learn how to help :evil:

However this regards entity interpolation and i’ve just done this mechanism.

What i need is simply how to compute physics on a target rigidbody escluding the other.

This is what is needed by my system client side prediction.



This trick let’s the local player see the result of his input immediatly and is done applying all the inputs instantly and storing them in a list.

When an update state message arrives, the state of the local player is treated in a different way then the remote players. In fact the correct state (last local player state sent by the server) represents the correct position in the past. Using a time system it is possible to retrieve the list of stored inputs that starts with the input corresponding to the time stamp of the correct state and then all those inputs are reapplyied to compute the new more correct predicted state.



@normen

This is called client side prediction, and as i said MK does not implement this system.

And as i said, i wanna only know how to manually compute physics. I’m not asking you how to solve my client side prediction. I DON’T WANT TO DO THIS THE WAY MONKEYZONE DOES.



Was i clear? Thankx