Skip to content

Commit c46f268

Browse files
committed
Improved the drift correction on the NetworkedNavMeshAgent
1 parent 7338299 commit c46f268

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

MLAPI/MonoBehaviours/Prototyping/NetworkedNavMeshAgent.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ public class NetworkedNavMeshAgent : NetworkedBehaviour
1111
public bool EnableProximity = false;
1212
public float ProximityRange = 50f;
1313
public float CorrectionDelay = 3f;
14+
//TODO rephrase.
15+
[Tooltip("Everytime a correction packet is recieved. This is the percentage (between 0 & 1) that we will move towards the goal.")]
16+
public float DriftCorrectionPercentage = 0.1f;
1417

1518
private static byte[] stateUpdateBuffer = new byte[36];
1619
private static byte[] correctionBuffer = new byte[24];
@@ -153,7 +156,7 @@ private void OnNavMeshCorrectionUpdate(int clinetId, byte[] data)
153156
Vector3 position = new Vector3(xPos, yPos, zPos);
154157

155158
agent.velocity = velocity;
156-
agent.Warp(position);
159+
agent.Warp(Vector3.Lerp(transform.position, position, DriftCorrectionPercentage));
157160
}
158161
}
159162
}

0 commit comments

Comments
 (0)