# PredictionRigidbody

Using PredictionRigidbody is very straight forward. In short, you move from applying force changes to the rigidbody onto the PredictionRigidbody instance instead.

View the [Creating Code](/docs/guides/features/prediction/creating-code.md) guide for using PredictionRigidbody in your replicate and reconcile methods.

## Using outside the script

As mentioned above you should always apply forces to the PredictionRigidbody rather than the Rigidbody directly. Our first guides demonstrate how to do this within the replicate method, as well how to reconcile using the PredictionRigidbody, but do not show how to add forces from outside scripts, such as a bumper in your game.

There is virtually no complexity to adding outside forces other than remembering to add them again, to the PredictionRigidbody and not the Rigidbody.

The example below is what it might look like if using a trigger on a world object to repel the player.

{% hint style="warning" %}
For triggers and collisions to work properly with prediction you must use our NetworkTrigger/NetworkCollision components. Otherwise, due to a Unity limitation, such interactions would not work. You can learn more about those components here.
{% endhint %}

{% hint style="success" %}
Fun fact: Fish-Networking is the only framework that has the ability to simulate Enter/Exit events with prediction; not even Fusion does this!
{% endhint %}

```csharp
private void NetworkTrigger_OnEnter(Collider other)
{
    // Add upward impulse when hitting this trigger.
    if (other.TryGetComponent<RigidbodyPlayer>(out rbPlayer))
        rbPlayer.PredictionRigidbody.AddForce(Vector3.up, ForceMode.Impulse);
    // Do not call Simulate on the PredictionRigidbody here. That should only be done
    // within the replicate method.
}
```

There is a fair chance a number of controllers will want to set velocities directly as well. PredictionRigidbody does support this. We encourage you to review the [PredictionRigidbody API](https://fish-networking.com/FishNet/api/api/FishNet.Object.Prediction.PredictionRigidbody.html#methods) for all available functionality.

Our last example demonstrates setting velocities directly.

{% hint style="info" %}
You would still call PredictionRigidbody.Simulate() regardless of how velocities are set.
{% endhint %}

```csharp
float horizontal = data.Horizontal;
Vector3 velocity = new Vector3(data.Horizontal, 0f, 0f) * _moveRate;
PredictionRigidbody.Velocity(velocity);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fish-networking.gitbook.io/docs/guides/features/prediction/predictionrigidbody.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
