Physics
Your scene's rigidbodies and colliders work as in Unity. Physics runs on each player's game, each for itself: a ball pushed on one game rolls on that game only. To show it to everyone, its owner syncs it (synced objects and values). The server has no physics: these calls are refused there.
using NodeWorld.Flux;
namespace MyWorld
{
public class Bumper : FluxScript
{
public float strength = 8f;
protected override void OnCollisionEnter(Collision collision)
{
if (collision.rigidbody == null) return;
var away = (collision.collider.transform.position - transform.position).normalized;
collision.rigidbody.AddForce(away * strength, ForceMode.VelocityChange);
}
}
}Rigidbodies
Rigidbody: velocity, angularVelocity, mass (above 0), isKinematic, useGravity, detectCollisions, constraints (RigidbodyConstraints.FreezePositionY…), interpolation, linearDamping, angularDamping, maxAngularVelocity, centerOfMass, and AddForce, AddTorque, AddForceAtPosition (with a ForceMode), MovePosition, MoveRotation, Sleep, WakeUp, IsSleeping.
Colliders
Collider: isTrigger, enabled, bounds. BoxCollider: center, size. SphereCollider: center, radius. MeshCollider: sharedMesh, convex (meshes made by scripts).
Rays and spheres
Physics.Raycast(origin, direction, out hit, maxDistance, layerMask) | The first collider along the ray: hit.point, hit.normal, hit.distance, hit.collider, hit.transform. Also with a Ray. |
Physics.RaycastAll(…) | Every collider along the ray, not sorted, 64 at most. |
Physics.CheckSphere(position, radius, layerMask) | A collider touches the sphere. |
Physics.OverlapSphere(position, radius, layerMask) | The colliders that touch it, 128 at most. |
Physics.gravity | The world's gravity. |
The layer mask is a bit per layer (1 << 9); Physics.DefaultRaycastLayers is every layer but Ignore Raycast, Physics.AllLayers every one. QueryTriggerInteraction.Ignore leaves trigger colliders out.
The avatars, portals and photo cameras NodeWorld puts in your scene are not hit: rays go through them (what a script cannot block).
Collisions and triggers
On the scripts of the object that has the collider:
| Callback | When |
|---|---|
OnTriggerEnter(Collider other), OnTriggerExit(Collider other) | A collider enters or leaves this trigger. |
OnCollisionEnter(Collision collision) | This object hits another collider: collision.collider, collision.relativeVelocity, collision.rigidbody (the other body, or null). OnCollisionEnter(Collider other) gives the collider alone. |
OnCollisionExit(Collider other) | They no longer touch. |
OnParticleCollision(GameObject other) | Particles hit this object (other: the particle system, whose Collision module sends collision messages). |
OnPlayerTriggerEnter(), OnPlayerTriggerExit() | The local player's body enters or leaves this trigger (interaction). |
Unity's rules apply: a trigger or a collision needs a rigidbody on one of the two objects. An event may give you a collider that is not your world's, such as a player's body: you can read it, not change it.
