Nebula
Loading...
Searching...
No Matches
PhysicsFeature.Physics Class Reference

Detailed Description

The managed side of the physics feature.

A body is named by the uint the PhysicsActor component holds, which is an id into the native actor pool. A script can hold an id across a rebuild and the entity it named can be gone by the time the call comes back, so the calls answer with an invalid value rather than asserting.

PhysX only allows reads of a body before simulate() and writes after fetchResults(), which is what the physics frame event is. The managed phase runs inside that event, after the step, so a read here sees this step and a write is picked up by the next one. A property that wants this phase can just override OnPhysicsFrame

Classes

class  Native

Static Public Member Functions

static bool IsActorValid (uint actorId)
 Whether the id is in the actor pool.
static float GetMass (uint actorId)
 The mass the body has.
static bool IsSleeping (uint actorId)
static void WakeUp (uint actorId)
static void Sleep (uint actorId)
static Vector3 GetVelocity (uint actorId)
static void SetVelocity (uint actorId, Vector3 velocity)
static Vector3 GetAngularVelocity (uint actorId)
static void SetAngularVelocity (uint actorId, Vector3 angularVelocity)
static void AddForce (uint actorId, Vector3 force)
 Newtons.
static void AddImpulse (uint actorId, Vector3 impulse)
 Mass times the velocity change.
static void AddImpulseAtPoint (uint actorId, Vector3 impulse, Vector3 point)
 Impulse at a point in world space, which is what gives the body angular velocity as well.
static void AddTorque (uint actorId, Vector3 torque)
static uint GetSceneForWorld (uint worldId)
 The physics scene a game world has.
static QueryFilter NewQueryFilter (uint group=0, uint mask=0xFFFFFFFF, uint excludeActorId=InvalidActorId)
 A filter with the values the native struct starts with.
static bool Raycast (Vector3 origin, Vector3 direction, float maxDistance, ref RaycastHit hit)
 Closest hit along a ray, on the default scene with a filter that accepts everything.
static bool Raycast (Vector3 origin, Vector3 direction, float maxDistance, ref RaycastHit hit, ref QueryFilter filter)
static bool Raycast (uint scene, Vector3 origin, Vector3 direction, float maxDistance, ref RaycastHit hit, ref QueryFilter filter)
static bool SegmentCast (Vector3 from, Vector3 to, ref RaycastHit hit)
 Closest hit along a segment, on the default scene with a filter that accepts everything.
static bool SegmentCast (Vector3 from, Vector3 to, ref RaycastHit hit, ref QueryFilter filter)
static bool SegmentCast (uint scene, Vector3 from, Vector3 to, ref RaycastHit hit, ref QueryFilter filter)
static bool SphereCast (Vector3 center, float radius, Vector3 direction, float maxDistance, ref ShapeCastHit hit)
 Closest hit along a swept sphere, on the default scene with a filter that accepts everything.
static bool SphereCast (Vector3 center, float radius, Vector3 direction, float maxDistance, ref ShapeCastHit hit, ref QueryFilter filter)
static bool SphereCast (uint scene, Vector3 center, float radius, Vector3 direction, float maxDistance, ref ShapeCastHit hit, ref QueryFilter filter)
static bool SphereCastAny (Vector3 center, float radius, Vector3 direction, float maxDistance, ref ShapeCastHit hit)
 First hit found along a swept sphere, which is not necessarily the closest.
static bool SphereCastAny (Vector3 center, float radius, Vector3 direction, float maxDistance, ref ShapeCastHit hit, ref QueryFilter filter)
static bool SphereCastAny (uint scene, Vector3 center, float radius, Vector3 direction, float maxDistance, ref ShapeCastHit hit, ref QueryFilter filter)
static bool BoxCast (Vector3 center, Quaternion orientation, Vector3 halfExtents, Vector3 direction, float maxDistance, ref ShapeCastHit hit)
 Closest hit along a swept box, on the default scene with a filter that accepts everything.
static bool BoxCast (Vector3 center, Quaternion orientation, Vector3 halfExtents, Vector3 direction, float maxDistance, ref ShapeCastHit hit, ref QueryFilter filter)
static bool BoxCast (uint scene, Vector3 center, Quaternion orientation, Vector3 halfExtents, Vector3 direction, float maxDistance, ref ShapeCastHit hit, ref QueryFilter filter)
static bool BoxCastAny (Vector3 center, Quaternion orientation, Vector3 halfExtents, Vector3 direction, float maxDistance, ref ShapeCastHit hit)
 First hit found along a swept box, which is not necessarily the closest.
static bool BoxCastAny (Vector3 center, Quaternion orientation, Vector3 halfExtents, Vector3 direction, float maxDistance, ref ShapeCastHit hit, ref QueryFilter filter)
static bool BoxCastAny (uint scene, Vector3 center, Quaternion orientation, Vector3 halfExtents, Vector3 direction, float maxDistance, ref ShapeCastHit hit, ref QueryFilter filter)
static bool IsCharacterValid (uint characterId)
 Whether the id is in the controller pool.
static Vector3 GetCharacterFootPosition (uint characterId)
 The lowest point of the character's collider in world space, which is what the entity's Position component holds.
static Vector3 GetCharacterCenterPosition (uint characterId)
 The center of the character's collider in world space.
static uint MoveCharacter (uint characterId, Vector3 displacement, float minDist, float timeSinceLastMove)
 The collision bits the move answered with.
static void SetCharacterPosition (uint characterId, Vector3 footPosition)
 Move the character to a foot position without checking for collisions.
static void SetCharacterHeight (uint characterId, float newHeight)
 Resize the character.

Static Public Attributes

const uint InvalidActorId = 0xFFFFFFFF
const uint InvalidScene = 0xFFFFFFFF
const uint InvalidCharacterId = 0xFFFFFFFF
const uint CharacterCollisionSides = 1 << 0
const uint CharacterCollisionUp = 1 << 1
const uint CharacterCollisionDown = 1 << 2

Properties

static uint DefaultScene [get]
 The physics scene the default world has.

Static Private Attributes

static uint defaultScene = InvalidScene

Member Function Documentation

◆ AddForce()

void PhysicsFeature.Physics.AddForce ( uint actorId,
Vector3 force )
inlinestatic

Newtons.

The force is accumulated by the body and integrated by the next step, so it is not the same quantity as an impulse.

◆ AddImpulse()

void PhysicsFeature.Physics.AddImpulse ( uint actorId,
Vector3 impulse )
inlinestatic

Mass times the velocity change.

A call here is what a step applies to the body immediately, which is the quantity a jump or a bounce is usually written in.

◆ AddImpulseAtPoint()

void PhysicsFeature.Physics.AddImpulseAtPoint ( uint actorId,
Vector3 impulse,
Vector3 point )
inlinestatic

Impulse at a point in world space, which is what gives the body angular velocity as well.

◆ AddTorque()

void PhysicsFeature.Physics.AddTorque ( uint actorId,
Vector3 torque )
inlinestatic

◆ BoxCast() [1/3]

bool PhysicsFeature.Physics.BoxCast ( uint scene,
Vector3 center,
Quaternion orientation,
Vector3 halfExtents,
Vector3 direction,
float maxDistance,
ref ShapeCastHit hit,
ref QueryFilter filter )
inlinestatic

◆ BoxCast() [2/3]

bool PhysicsFeature.Physics.BoxCast ( Vector3 center,
Quaternion orientation,
Vector3 halfExtents,
Vector3 direction,
float maxDistance,
ref ShapeCastHit hit )
inlinestatic

Closest hit along a swept box, on the default scene with a filter that accepts everything.

The orientation is the orientation of the box at the start of the cast, and the box does not rotate while it is swept. Distance is measured from the center of the box, so a box with half extents of 1 whose center is 5 from a surface reports 4. See the remarks on SphereCast for what a hit that started inside geometry answers with.

◆ BoxCast() [3/3]

bool PhysicsFeature.Physics.BoxCast ( Vector3 center,
Quaternion orientation,
Vector3 halfExtents,
Vector3 direction,
float maxDistance,
ref ShapeCastHit hit,
ref QueryFilter filter )
inlinestatic

◆ BoxCastAny() [1/3]

bool PhysicsFeature.Physics.BoxCastAny ( uint scene,
Vector3 center,
Quaternion orientation,
Vector3 halfExtents,
Vector3 direction,
float maxDistance,
ref ShapeCastHit hit,
ref QueryFilter filter )
inlinestatic

◆ BoxCastAny() [2/3]

bool PhysicsFeature.Physics.BoxCastAny ( Vector3 center,
Quaternion orientation,
Vector3 halfExtents,
Vector3 direction,
float maxDistance,
ref ShapeCastHit hit )
inlinestatic

First hit found along a swept box, which is not necessarily the closest.

See the remarks on SphereCastAny.

◆ BoxCastAny() [3/3]

bool PhysicsFeature.Physics.BoxCastAny ( Vector3 center,
Quaternion orientation,
Vector3 halfExtents,
Vector3 direction,
float maxDistance,
ref ShapeCastHit hit,
ref QueryFilter filter )
inlinestatic

◆ GetAngularVelocity()

Vector3 PhysicsFeature.Physics.GetAngularVelocity ( uint actorId)
inlinestatic

◆ GetCharacterCenterPosition()

Vector3 PhysicsFeature.Physics.GetCharacterCenterPosition ( uint characterId)
inlinestatic

The center of the character's collider in world space.

◆ GetCharacterFootPosition()

Vector3 PhysicsFeature.Physics.GetCharacterFootPosition ( uint characterId)
inlinestatic

The lowest point of the character's collider in world space, which is what the entity's Position component holds.

◆ GetMass()

float PhysicsFeature.Physics.GetMass ( uint actorId)
inlinestatic

The mass the body has.

This is the mass PhysX resolved, which is not the same as the Rigidbody component's mass: the component defaults to 0 and the mass is then derived from the shape volumes and the material densities.

◆ GetSceneForWorld()

uint PhysicsFeature.Physics.GetSceneForWorld ( uint worldId)
inlinestatic

The physics scene a game world has.

◆ GetVelocity()

Vector3 PhysicsFeature.Physics.GetVelocity ( uint actorId)
inlinestatic

◆ IsActorValid()

bool PhysicsFeature.Physics.IsActorValid ( uint actorId)
inlinestatic

Whether the id is in the actor pool.

A static, kinematic or dynamic actor is in it, and an entity that has a PhysicsActor component but has not been built yet is not.

◆ IsCharacterValid()

bool PhysicsFeature.Physics.IsCharacterValid ( uint characterId)
inlinestatic

Whether the id is in the controller pool.

An entity with a Character component that has not been built yet is not, because the component is filled by the feature on the physics frame.

◆ IsSleeping()

bool PhysicsFeature.Physics.IsSleeping ( uint actorId)
inlinestatic

◆ MoveCharacter()

uint PhysicsFeature.Physics.MoveCharacter ( uint characterId,
Vector3 displacement,
float minDist,
float timeSinceLastMove )
inlinestatic

The collision bits the move answered with.

Bit 0 is sides, bit 1 up and bit 2 down, and the down bit is what a grounded check reads.

A character controller is moved by a displacement, not by a velocity, and the move happens outside the step. The character's actor is in the actor pool, but its velocity is not what the controller moved by, so a character is read through its component rather than through the velocity calls.

◆ NewQueryFilter()

QueryFilter PhysicsFeature.Physics.NewQueryFilter ( uint group = 0,
uint mask = 0xFFFFFFFF,
uint excludeActorId = InvalidActorId )
inlinestatic

A filter with the values the native struct starts with.

A C# struct cannot give its fields default values, so a new QueryFilter() has mask 0 and excludeActorId 0. Native starts with every group accepted and no actor excluded, which is not what a fresh struct gives, so build a filter with this rather than with new.

◆ Raycast() [1/3]

bool PhysicsFeature.Physics.Raycast ( uint scene,
Vector3 origin,
Vector3 direction,
float maxDistance,
ref RaycastHit hit,
ref QueryFilter filter )
inlinestatic

◆ Raycast() [2/3]

bool PhysicsFeature.Physics.Raycast ( Vector3 origin,
Vector3 direction,
float maxDistance,
ref RaycastHit hit )
inlinestatic

Closest hit along a ray, on the default scene with a filter that accepts everything.

The direction has to be normalized. A ground check needs a filter that excludes its own actor, because the ray starts inside the shape the caller owns.

◆ Raycast() [3/3]

bool PhysicsFeature.Physics.Raycast ( Vector3 origin,
Vector3 direction,
float maxDistance,
ref RaycastHit hit,
ref QueryFilter filter )
inlinestatic

◆ SegmentCast() [1/3]

bool PhysicsFeature.Physics.SegmentCast ( uint scene,
Vector3 from,
Vector3 to,
ref RaycastHit hit,
ref QueryFilter filter )
inlinestatic

◆ SegmentCast() [2/3]

bool PhysicsFeature.Physics.SegmentCast ( Vector3 from,
Vector3 to,
ref RaycastHit hit )
inlinestatic

Closest hit along a segment, on the default scene with a filter that accepts everything.

The segment is the direction and the distance, so a caller that has two points does not have to normalize them first.

◆ SegmentCast() [3/3]

bool PhysicsFeature.Physics.SegmentCast ( Vector3 from,
Vector3 to,
ref RaycastHit hit,
ref QueryFilter filter )
inlinestatic

◆ SetAngularVelocity()

void PhysicsFeature.Physics.SetAngularVelocity ( uint actorId,
Vector3 angularVelocity )
inlinestatic

◆ SetCharacterHeight()

void PhysicsFeature.Physics.SetCharacterHeight ( uint characterId,
float newHeight )
inlinestatic

Resize the character.

The position is adjusted so it does not pop into the air.

◆ SetCharacterPosition()

void PhysicsFeature.Physics.SetCharacterPosition ( uint characterId,
Vector3 footPosition )
inlinestatic

Move the character to a foot position without checking for collisions.

This is a teleport, so a character placed inside geometry stays there until the next move.

◆ SetVelocity()

void PhysicsFeature.Physics.SetVelocity ( uint actorId,
Vector3 velocity )
inlinestatic

◆ Sleep()

void PhysicsFeature.Physics.Sleep ( uint actorId)
inlinestatic

◆ SphereCast() [1/3]

bool PhysicsFeature.Physics.SphereCast ( uint scene,
Vector3 center,
float radius,
Vector3 direction,
float maxDistance,
ref ShapeCastHit hit,
ref QueryFilter filter )
inlinestatic

◆ SphereCast() [2/3]

bool PhysicsFeature.Physics.SphereCast ( Vector3 center,
float radius,
Vector3 direction,
float maxDistance,
ref ShapeCastHit hit )
inlinestatic

Closest hit along a swept sphere, on the default scene with a filter that accepts everything.

Distance is how far the shape travelled, measured from its center rather than from its surface, so a radius 1 sphere whose center is 5 from a surface reports 4. The hit point is the contact point, which is a different number. A shape that already overlaps geometry at the start reports distance 0, and its normal is the reverse of the cast direction rather than a surface normal. A box cast is a few thousandths short, because PhysX uses an edge tolerance for a box against a box.

◆ SphereCast() [3/3]

bool PhysicsFeature.Physics.SphereCast ( Vector3 center,
float radius,
Vector3 direction,
float maxDistance,
ref ShapeCastHit hit,
ref QueryFilter filter )
inlinestatic

◆ SphereCastAny() [1/3]

bool PhysicsFeature.Physics.SphereCastAny ( uint scene,
Vector3 center,
float radius,
Vector3 direction,
float maxDistance,
ref ShapeCastHit hit,
ref QueryFilter filter )
inlinestatic

◆ SphereCastAny() [2/3]

bool PhysicsFeature.Physics.SphereCastAny ( Vector3 center,
float radius,
Vector3 direction,
float maxDistance,
ref ShapeCastHit hit )
inlinestatic

First hit found along a swept sphere, which is not necessarily the closest.

This is the fast path for a caller that only needs to know that something is in the way, such as a line of sight check. Use SphereCast when the caller needs the closest hit or the distance.

◆ SphereCastAny() [3/3]

bool PhysicsFeature.Physics.SphereCastAny ( Vector3 center,
float radius,
Vector3 direction,
float maxDistance,
ref ShapeCastHit hit,
ref QueryFilter filter )
inlinestatic

◆ WakeUp()

void PhysicsFeature.Physics.WakeUp ( uint actorId)
inlinestatic

Member Data Documentation

◆ CharacterCollisionDown

const uint PhysicsFeature.Physics.CharacterCollisionDown = 1 << 2
static

◆ CharacterCollisionSides

const uint PhysicsFeature.Physics.CharacterCollisionSides = 1 << 0
static

◆ CharacterCollisionUp

const uint PhysicsFeature.Physics.CharacterCollisionUp = 1 << 1
static

◆ defaultScene

uint PhysicsFeature.Physics.defaultScene = InvalidScene
staticprivate

◆ InvalidActorId

const uint PhysicsFeature.Physics.InvalidActorId = 0xFFFFFFFF
static

◆ InvalidCharacterId

const uint PhysicsFeature.Physics.InvalidCharacterId = 0xFFFFFFFF
static

◆ InvalidScene

const uint PhysicsFeature.Physics.InvalidScene = 0xFFFFFFFF
static

Property Documentation

◆ DefaultScene

uint PhysicsFeature.Physics.DefaultScene
staticget

The physics scene the default world has.


The documentation for this class was generated from the following file:
  • /github/workspace/code/addons/physicsfeature/scriptapi/Physics.cs