Skip to main content

NetworkGravity

A class in Root.Township, Alta.Networking.

Replaces Unity gravity on a rigidbody with a ConstantForce, so gravity and drag can be changed per object and synced to clients.

Constructors​

MemberWhat it is
NetworkGravity()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

3 private and internal fields
MemberWhat it is
private Rigidbody cachedRigidbodyThe rigidbody whose drag is synced.
private ConstantForce gravityThe constant force used as gravity.
private MethodSync syncGravityMethod sync for gravity and drag.

Properties​

MemberWhat it is
float Drag { get; set; }The rigidbody's drag. Setting it sends the new values to clients.
float Gravity { get; set; }Vertical gravity force. Setting it sends the new values to clients.

Methods​

MemberWhat it is
override void Initialize()Creates the gravity method sync.
override void OnConnected(Player player)Sends the gravity and drag to a newly connected player.
void Reset()Sets gravity back to the normal physics gravity.
2 private and internal methods
MemberWhat it is
private bool EditorSetup()Editor: adds the constant force set to normal gravity and turns off the rigidbody's own gravity.
private void Sync(IPlayer player, Stream stream)Sends or receives gravity (-10 to 10) and drag (0 to 5), both in steps of 0.1.