custom physics network prediction

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

SoSilencer

Harry Goz (1932 - 2003)
Nov 27, 2000
834
0
0
42
unrealdev.net
Here's a tough one for you. I've got a space ship that has a full 6 axis control system. It's custom coded with real physics equations, not karma or anything else.

Unlike the standard walking players who only have forwards/backwards and left/right for movement with pitch up/down and yaw left/right for rotation, I have 6 axis. That means the ships can be moved forwards/backwards, left/right or up/down and can be rotated with pitch up/down, yaw left/right and roll left/right. All of it works offline properly (though I probably need to recode it for effeciency) but online is another story. The actual mechanism as to how this works is quite simple. The inputs you pressed are passed to the ship which then activates each of the thrusters on the ship responsible for that movement. Each individual thruster then applies a force to the ship and all of these forces are added together to find the new movement and rotation. Pretty cool stuff, but I've got no clue how to make it work online.

Does anyone know how this sort of thing is done and could help me out? I doubt I'll be able to find somebdoy who is willing to do this for me so I'm trying to figure out how to do it myself but so far no luck, I'm totally lost here, so any help would be appreciated.
 

BlackHornet

Global Warzone Project Leader
Apr 24, 2002
76
0
0
43
Aachen - Germany
www.hornet-maps.de
have a look into the ReplicateMove, ServerMove, ProcessMove funktions in the PlayerController, if there any limiteds are given.

I would suggest to write own Move function in your case. So you have complete free control
 

SoSilencer

Harry Goz (1932 - 2003)
Nov 27, 2000
834
0
0
42
unrealdev.net
Yes but my problem is that I have no clue how to do this. I've looked at those functions several times and it all goes over my head I just don't understand what is happening and there's no way I could write my own until I do. Would you or anybody else be able to give a brief (or detailed if possible) explination of how it all works? Once I know how it works I shouldn't have too much trouble coding my own custom version.

An alternative solution is to find somebody who can do it for me. I would of course compensate this person for their work, though the exact details and method would have to be worked out.
 

BlackHornet

Global Warzone Project Leader
Apr 24, 2002
76
0
0
43
Aachen - Germany
www.hornet-maps.de
its in the PlayerController.uc

function ServerMove(....)

Code:
function ServerMove(...)
{
    .....
        ViewRot.Pitch = ViewPitch;
    ViewRot.Yaw = ViewYaw;
    ViewRot.Roll = 0;
    SetRotation(ViewRot);

    if ( Pawn != None )
    {
        Rot.Roll = 256 * ClientRoll;
        Rot.Yaw = ViewYaw;
        if ( (Pawn.Physics == PHYS_Swimming) || (Pawn.Physics == PHYS_Flying) )
            maxPitch = 2;
        else
            maxPitch = 0;
        If ( (ViewPitch > maxPitch * RotationRate.Pitch) && (ViewPitch < 65536 - maxPitch * RotationRate.Pitch) )
        {
            If (ViewPitch < 32768)
                Rot.Pitch = maxPitch * RotationRate.Pitch;
            else
                Rot.Pitch = 65536 - maxPitch * RotationRate.Pitch;
        }
        else
            Rot.Pitch = ViewPitch;
        DeltaRot = (Rotation - Rot);
        Pawn.SetRotation(Rot);
    }
    .....
}

must have a look there

maybe you have to override these servermove in your movement state class and it should work....

check you set an ViewRot.Roll != 0 and an Rot != 0 so the pawn rotates too and not only the view ;)
 

SoSilencer

Harry Goz (1932 - 2003)
Nov 27, 2000
834
0
0
42
unrealdev.net
It's a lot more involved in that I think. What about timestamping the moves? What about correcting for lost packets? The default stuff has lots of code regarding dodges and jumps, neither of which would apply, and has no code dealing with the extra axis I have for both movement and rotation.

Now I did notice something I've never seen before and that's a large section of comments regarding network replication. I'm not quite sure how I missed it but I did, so I'll read over everything a few more times and try to figure it out. Stilll, I'm in pretty far over my head so any other help is appreciated.

Code:
/*
========================================================================
Here's how player movement prediction, replication and correction works in network games:

Every tick, the PlayerTick() function is called.  It calls the PlayerMove() function (which is implemented
in various states).  PlayerMove() figures out the acceleration and rotation, and then calls ProcessMove()
(for single player or listen servers), or ReplicateMove() (if its a network client).

ReplicateMove() saves the move (in the PendingMove list), calls ProcessMove(), and then replicates the move
to the server by calling the replicated function ServerMove() - passing the movement parameters, the client's
resultant position, and a timestamp.

ServerMove() is executed on the server.  It decodes the movement parameters and causes the appropriate movement
to occur.  It then looks at the resulting position and if enough time has passed since the last response, or the
position error is significant enough, the server calls ClientAdjustPosition(), a replicated function.

ClientAdjustPosition() is executed on the client.  The client sets its position to the servers version of position,
and sets the bUpdatePosition flag to true.

When PlayerTick() is called on the client again, if bUpdatePosition is true, the client will call
ClientUpdatePosition() before calling PlayerMove().  ClientUpdatePosition() replays all the moves in the pending
move list which occured after the timestamp of the move the server was adjusting.
*/
 

SoSilencer

Harry Goz (1932 - 2003)
Nov 27, 2000
834
0
0
42
unrealdev.net
Well from what I've picked up after re-reading the code this is how I was thinking it should be done, please tell me if this seems wrong. As I mentioned before the player has 12 inputs to control the 6 axis. These inputs in turn activate the appropriate thrusters on the ship to acheive that movement. Since the actual movement is directly dependant on exactly which thrusters fire, and which thrusters fire is directly dependant upon which inputs are active, these will need to be sent to the server. This will either be 2 floats and 4 bytes or 6 floats. The server then has to calculate the physics to make sure it's done properly. I guess in order to check the error I would also have to send the ships position, acceleration, and rotation to the server so that the server could check for errors or out of sync.

There just isn't any way for the server to calculate the physics without knowing which inputs are active. Everything relies on which thrusters are active, when and for how long. The question is, what's the best way to get that information to the server and, eventually, to all the other clients so they can play the proper special effects.