Motion Prediction
Summary
Shows how to customise entity movement prediction using predictors.
Configure predictors using predictor assets.
Give an overview of the built-in predictors.
Configure which properties are predicted and their prediction behaviour.
Create a basic custom predictor that uses
Vector3.SmoothDampon position and linearly interpolates rotation.
Predictor Assets
Predictors are used to predict or smooth entity motion. Predictors receive server transform and property updates, and control the transform and property values on the client. You can change the default predictors in the 'Default Predictors' section of the ksRoomType component. There are four predictor fields:
Entity The default predictor to use for entities that do not use input prediction. By default this is 'DefaultLinearPredictor'.
Controller The default predictor to use for entities controlled by the local player. By default this is 'DefaultConvergingInputPredictor' If the player controller has
ksPlayerController.UseInputPredictionset to false, the controlled entity will use the 'Entity' predictor instead.Room The predictor for predicting room properties. By default this is none, which means room properties are not predicted.
Player The predictor for predicting player properties. By default this is none, which means player properties are not predicted.
You can assign different predictors to an entity using the following fields in the ksEntityComponent inspector:
Predictor The predictor to use when the entity is not controlled by the local player. If the checkbox is unchecked, it will use the default 'Entity' predictor from the ksRoomType.
Controller Predictor The predictor to use when the entity is controlled by the local player. If the checkbox is unchecked, it will use the default 'Controller' predictor from the ksRoomType.
Some predictors, such as the ksConvergingInputPredictor, can only be used with player controllers and can only be assigned to the ksRoomType's 'Controller' field or the entity's 'Controller Predictor'.
Predictor types
ksLinearPredictor
ksLinearPredictor is the default predictor for entities without player controllers. It will linearly interpolate between each server position. If it reaches the last known server position before a new server position is received, it continues to linearly extrapolate. The linear predictor uses the ksTimeKeeper to determine which point in time to render the entity at. This ensures all entities using the linear predictor are rendered at the same point in time. The time keeper has some properties you can set to configure the behaviour of the linear predictor. Create a linear predictor asset whose properties you can edit by right-clicking in the project window and selecting 'Create->Reactor->Linear Predictor', or use the built-in 'DefaultLinearPredictor' asset.
Connect Script
Entities that have owners with the ksOwnerPermissions.TRANSFORM permission use client-authoritative movement. They use a different time keeper that uses time deltas synced from the player who owns the entity. You can access an owning player's time data and time keeper using Room.GetTime(playerId) and (ksTimeKeeper)Room.GetTime(playerId).Adjuster.
ksConvergingInputPredictor
ksConvergingInputPredictor is the default predictor for entities with player controllers that use input prediction. Accelerations are slower than on the server so that the client and server will converge. Create a converging input predictor asset whose properties you can edit by right-clicking in the project window and selecting 'Create->Reactor->Converging Input Predictor', or use the built-in 'DefaultConvergingInputPredictor' asset.
ksClientInputPredictor
ksClientInputPredictor Predicts movement and properties using only the player controller; server data is ignored. This is mostly useful for debugging the see how your player controlled entity behaves on the client without influence from the server.
Predicting Properties
Predictors can predict property values as well as transform data. To predict properties using a linear predictor or converging input predictor, you will need to create a linear predictor asset ('Create/Reactor/Linear Predictor') or converging input predictor asset ('Create->Reactor->Converging Input Predictor'), and configure the Predicted Properties in the inspector with the properties you want to predict. Each property has a 'Type' that determines how the property will be predicted. It can be set to one of the following:
Linear Float - Use linear interpolation on a float.
Linear Vector2 - Use linear interpolation on a ksVector2.
Linear Vector3 - Use linear interpolation on a ksVector3.
Linear Color - Use linear interpolation on a ksColor.
Wrap Float - Use linear interpolation on a float and wrap onto a range defined by a min and max value.
Spherical Vector2 - Use spherical interpolation on a ksVector2.
Spherical Vector3 - Use spherical interpolation on a ksVector3.
Quaternion - Use spherical interpolation on a ksQuaternion.
Client - The client player controller has full control over the local property value. If the controller does not set the property value, the server value is used. The server is still authoritative; the client does not decide what other clients see.
Changing Predictors at Runtime
To change the predictor used by an entity at runtime, assign a predictor to ksEntity.InputPredictor if the entity is controlled by the local player, and ksEntity.NonInputPredictor if it is not. ksEntity.Predictor is the active preditor the entity is using. You can change the predictor used for room or player properties by assigning ksRoom.Predictor or ksPlayer.Predictor.
Set ksEntity.PredictionEnabled to enable or disable prediction for an entity at runtime. When prediction is disabled the entity will not use either the InputPredictor or the NonInputPredictor and ksEntity.Predictor will be null.
The following room script shows how to dynamically disable prediction for distant entities. For large worlds with thousands of moving entities, this can improve the performance of the client.
Client Room Script
Custom Predictors
To create your own predictor script, right-click in the project browser. Select 'Create->Reactor->Predictor'. The following is a very basic sample predictor that update the entity's position using Vector3.SmoothDamp, linearly interpolates rotation, and updates a float property with id 0 using Mathf.SmoothDamp. It can be used with or without a player controller, or just to predict property 0 on a room or player. To create an asset from it that can be assigned to an entity or as a default predictor in the room type, right-click in the project browser and select 'Create->Reactor->SamplePredictor'.
Sample Predictor
Last updated

