20
20
[ NetworkSettings ( channel = 1 , sendInterval = 0.33f ) ]
21
21
public class CharacterNetworkInput : NetworkBehaviour {
22
22
23
- private const float MAX_CLIENT_WAITING_STATES = 25 ; //How many states to keep on client
23
+ private const float MAX_CLIENT_WAITING_STATES = 30 ; //How many states to keep on client
24
24
private const float MAX_CLIENT_DISTANCE_WARNING = 0.25f ; //Max distance between server and localy calculated position
25
25
private const float MAX_SERVER_DISTANCE_SNAP = 0.15f ; //Max distance between client and server calculated position before SNAPPING
26
26
@@ -38,6 +38,7 @@ public class CharacterNetworkInput : NetworkBehaviour {
38
38
private CharacterMovement characterMovement ;
39
39
private CharacterRotation characterRotation ;
40
40
41
+ private float nextSendTime ; //CLIENT SIDE time when the client must send data to server
41
42
private Queue < CharacterInput . InputState > inputStates ; //CLIENT SIDE input states not ack by server
42
43
43
44
private Vector3 serverLastRecvPosition ; //CLIENT SIDE last received pos from server
@@ -76,19 +77,24 @@ void FixedUpdate () {
76
77
characterMovement . RunUpdate ( Time . fixedDeltaTime ) ;
77
78
characterRotation . RunUpdate ( Time . fixedDeltaTime ) ;
78
79
//Client: Trim commands to 25 and send commands to server
80
+ Debug . Log ( inputStates . Count ) ;
79
81
if ( inputStates . Count > MAX_CLIENT_WAITING_STATES ) {
80
82
Debug . LogError ( "Too many waiting states, starting to drop frames" ) ;
81
83
}
82
84
while ( inputStates . Count > MAX_CLIENT_WAITING_STATES ) { inputStates . Dequeue ( ) ; }
83
- CmdSetServerInput ( inputStates . ToArray ( ) , transform . position ) ;
85
+ if ( nextSendTime < Time . time )
86
+ {
87
+ CmdSetServerInput ( inputStates . ToArray ( ) , transform . position ) ;
88
+ nextSendTime = Time . time + 0.33f ;
89
+ }
84
90
}
85
91
}
86
92
87
93
/// <summary>
88
94
/// Server: Receive a list of inputs from the client
89
95
/// </summary>
90
96
/// <param name="newInputs"></param>
91
- [ Command ]
97
+ [ Command ( channel = 1 ) ]
92
98
void CmdSetServerInput ( CharacterInput . InputState [ ] newInputs , Vector3 newClientPos )
93
99
{
94
100
int index = 0 ;
0 commit comments