Manually update physics (45 posts)

  • Profile picture of kazeshiro kazeshiro6p said 3 months, 3 weeks ago:

    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 :-)

  • Profile picture of normen normen1290p said 3 months, 3 weeks ago:

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

  • Profile picture of kazeshiro kazeshiro6p said 3 months, 3 weeks ago:

    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.

    currentState;
    inputList;
    while(inputList is not empty) {
        serverState = updateState(serverState, nextInput) ;
    }
    
    currentState = serverState;
    

    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

  • Profile picture of normen normen1290p said 3 months, 3 weeks ago:

    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.

  • Profile picture of kazeshiro kazeshiro6p said 3 months, 3 weeks ago:

    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

  • Profile picture of normen normen1290p said 3 months, 3 weeks ago:

    As said, MonkeyZone has this laid out.

  • Profile picture of kazeshiro kazeshiro6p said 3 months, 3 weeks ago:

    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 :-)

  • Profile picture of normen normen1290p said 3 months, 3 weeks ago:

    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.

  • Profile picture of kazeshiro kazeshiro6p said 3 months, 3 weeks ago:

    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?

  • Profile picture of normen normen1290p said 3 months, 3 weeks ago:

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

  • Profile picture of kazeshiro kazeshiro6p said 3 months, 3 weeks ago:

    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 :-)

  • Profile picture of normen normen1290p said 3 months, 3 weeks ago:

    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.

  • Profile picture of kazeshiro kazeshiro6p said 3 months, 3 weeks ago:

    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

  • Profile picture of survivor survivor106p said 3 months, 3 weeks ago:

    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.

  • Profile picture of kazeshiro kazeshiro6p said 3 months, 3 weeks ago:

    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:

    CharacterControl.setPhysicsLocation(stateSentByServer.getPhysicsLocation);
    While(!inputList.isEmpty()) {
        CharacterControl.setForce(input.getForce);
        CharacterControl.update(input.getDeltaTime);
    }
    

    But i don’t know how to do this