Represents a physics world: a collection of interacting physics objects where Actors live.
In the Stingray engine, exactly one PhysicsWorld is associated with each game World.
Constructors and accessors
Related sample code
Other related reference items
Related help topics
apply_wind ( self, vf, id )Applies the wind from the VectorField to the actors in the world that collide with the specified collision filter.
|
self : | Specifies the object instance that this function will act on. You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation. | |
vf : | A vector field from which a wind is applied. | |
id : | string | The id of the collision filter with which the actors collide. |
This function does not return any values. |
Call this function every frame if you want to continously apply a vector field wind to a physics world.
Note that the wind is only applied to actors that are awake. The reason is that otherwise the wind would keep every actor in the level awake, which would have severe effects on the physics performance.
If you play a strong short-lived wind effect (such an explosion), you should make sure to wake all actors that can be affected by the explosion. Otherwise, the explosion would not move the sleeping actors. Use the function wake_actors() to wake sleeping actors.
Other related reference items
break_joints ( self, u1, ac1, u2, ac2 )Breaks the joints between two connected actors that are not in the scene, typically because they are currently disabled.
|
self : | Specifies the object instance that this function will act on. You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation. | |
u1 : | The Unit to which the first actor belongs. | |
ac1 : | string | The name of the first actor. |
u2 : | The Unit to which the second actor belongs. | |
ac2 : | string | The name of the second actor. |
This function does not return any values. |
break_joints ( self, ac1, ac2 )Breaks the joints between the two specified actors.
|
self : | Specifies the object instance that this function will act on. You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation. | |
ac1 : | The first joined actor. | |
ac2 : | The second joined actor. |
This function does not return any values. |
For example, this can be used to dismember ragdolls.
create_joint ( self, type, actor_1, pose_1, actor_2, pose_2 ) : stingray.JointCreates a physics joint between two actors in the world.
|
self : | Specifies the object instance that this function will act on. You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation. | |
type : | The type of joint. Must be one of the Joint.Type enum values: SPHERICAL, REVOLUTE, PRISMATIC, FIXED, DISTANCE or D6. | |
actor_1 : | any(stingray.Actor, nil) | The first actor to participate in the joint. Can be nil to join objects to the world. The any(...) notation indicates that this item may be an instance of any of the types shown in the parentheses. |
pose_1 : | Joint orientation in actor_1 local frame. | |
actor_2 : | any(stingray.Actor, nil) | The second actor to participate in the joint. Can be nil to join objects to the world. The any(...) notation indicates that this item may be an instance of any of the types shown in the parentheses. |
pose_2 : | Joint orientation in actor_2 local frame. |
The newly spawned joint. |
Use destroy_joint() to destroy it
Other related reference items
destroy_actor ( self, actor ) |
self : | Specifies the object instance that this function will act on. You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation. | |
actor : | The dynamic actor to destroy. |
This function does not return any values. |
Do not use this function to destroy Actors that belong to Units.
destroy_joint ( self, joint )Destroys a dynamic joint that was created with create_joint().
|
self : | Specifies the object instance that this function will act on. You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation. | |
joint : | The dynamic joint to destroy. |
This function does not return any values. |
Do not use this function to destroy joints that belong to Units.
Other related reference items
linear_capsule_sweep ( self, from, to, rotation, radius, half_height, max_hits, sweep_params ) : collision_hit[]Performs a linear sweep through space with an oriented capsule.
|
self : | Specifies the object instance that this function will act on. You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation. | |
from : | The starting point of the swept capsule. | |
to : | The ending point of the swept capsule. | |
rotation : | The rotation of the capsule. By default, the capsule is oriented with its length along the X axis. | |
radius : | number | The radius of the capsule. |
half_height : | number | The distance from the mid-point to the outer top or bottom of the capsule. |
max_hits : | integer | The maximum number of hits to report. Must be greater than zero. |
sweep_params : | string+ | A list of parameters for the sweep. The possible parameters are:
The + notation indicates that there may be one or more instances of the specified type. |
A table that contains an array of collision_hit tables, each of which records one collision point along the sweep. The [] notation indicates that this type is an array: a table in which the keys of the members are sequential integers, and the value of each element is an instance of the type shown. |
linear_obb_sweep ( self, from, to, extents, rotation, max_hits, sweep_params ) : collision_hit[]Performs a linear sweep through space with an oriented bounding box.
|
self : | Specifies the object instance that this function will act on. You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation. | |
from : | The starting point of the center of the box. | |
to : | The ending point of the center of the box. | |
extents : | The extents of the box in the three dimensions. | |
rotation : | The rotation of the box in world space. | |
max_hits : | integer | The maximum number of hits to report. |
sweep_params : | string+ | A list of parameters for the sweep. The possible parameters are:
The + notation indicates that there may be one or more instances of the specified type. |
A table that contains an array of collision_hit tables, each of which records one collision point along the sweep. The [] notation indicates that this type is an array: a table in which the keys of the members are sequential integers, and the value of each element is an instance of the type shown. |
linear_sphere_sweep ( self, from, to, radius, max_hits, sweep_params ) : collision_hit[]Performs a linear sweep through space with a sphere.
|
self : | Specifies the object instance that this function will act on. You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation. | |
from : | The starting point of the sphere. | |
to : | The ending point of the sphere. | |
radius : | number | The radius of the sphere. |
max_hits : | integer | The maximum number of hits to report. |
sweep_params : | string+ | A list of parameters for the sweep. The possible parameters are:
The + notation indicates that there may be one or more instances of the specified type. |
A table that contains an array of collision_hit tables, each of which records one collision point along the sweep. The [] notation indicates that this type is an array: a table in which the keys of the members are sequential integers, and the value of each element is an instance of the type shown. |
make_raycast ( self, callback, params ) : stingray.RaycastCreates a Raycast object that can be used to make collision tests against physics objects.
|
self : | Specifies the object instance that this function will act on. You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation. | |
callback : | fun(any(boolean, collision_hit[]), stingray.Vector3?, number?, stingray.Vector3?, stingray.Actor?:nil)? | A function that will be called when each collision test made by the returned Raycast object is completed. If this value is omitted, the raycasts you carry out using the returned Raycast object will be performed synchronously. See the description of the Raycast object for full details. The any(...) notation indicates that this item may be an instance of any of the types shown in the parentheses. The fun(...) notation indicates that this is a function that accepts parameters of the types shown to the left of the colon :, and that returns the types shown to the right of the colon.. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
params : | string* | A list of parameters that control the collision tests carried out by the Raycast object. See the description of the Raycast object for full details. The * notation indicates that there may be zero or more instances of the specified type. |
The newly created Raycast object. |
See the Raycast description for details on using the returned object to carry out a collision test.
Other related reference items
overlap ( self, callback, params ) : tablePerforms an overlap test in the physics world: a collision test that finds all the actors in the world that are within a specified shape.
|
self : | Specifies the object instance that this function will act on. You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation. | |
callback : | fun(stingray.Actor[]:nil) | A callback function that is called when the overlap test is completed. This function is passed a table that contains an array of all Actor objects found by the test. The fun(...) notation indicates that this is a function that accepts parameters of the types shown to the left of the colon :, and that returns the types shown to the right of the colon.. |
params : | any+ | Specifies the shape of the overlap. Possible values are:
The + notation indicates that there may be one or more instances of the specified type. |
table |
An internal opaque object that represents the overlap test. |
For example, you could find all actors in a 20-meter sphere around the player.
raycast ( self, start, dir, length, params ) : any(boolean, collision_hit[]), stingray.Vector3?, number?, stingray.Vector3?, stingray.Actor?Tests for collisions with the physics objects that live in the same PhysicsWorld.
|
self : | Specifies the object instance that this function will act on. You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation. | |
start : | Specifies the starting position for the raycast. | |
dir : | Specifies the direction that the ray will be cast from its starting point. | |
length : | number? | Optional. Specifies the maximum length of the ray. If not specified, the ray will be infinitely long. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
params : | string* | A list of parameters that control the collision tests and determine what return values this function will produce. See the Raycast object description for full details. The * notation indicates that there may be zero or more instances of the specified type. |
any(boolean, collision_hit[]) |
Whether or not a collision occurred. The any(...) notation indicates that this item may be an instance of any of the types shown in the parentheses. |
Position of the collision. The ? notation indicates that this type is optional: there may be zero or one instances of it. | |
number? |
Distance to collision. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
Normal of collision surface. The ? notation indicates that this type is optional: there may be zero or one instances of it. | |
Actor that was hit. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
The raycast will be run immediately and the results of the collision test will be returned by this function. See the description of the Raycast object for details about how to interpret the return values.
Related sample code
Other related reference items
set_debug_draw ( self, enable )Enables or disables debug drawing for this world.
|
self : | Specifies the object instance that this function will act on. You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation. | |
enable : | boolean | A flag to enable or disable debug drawing. |
This function does not return any values. |
set_gravity ( self, gravity )Sets the gravity in the specified PhysicsWworld, expressed as a Vector3.
|
self : | Specifies the object instance that this function will act on. You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation. | |
gravity : | The new gravity value to set for the world. |
This function does not return any values. |
The default gravity is Vector3(0,0,-9.82).
set_observer ( self, mat )Sets the observer for the physics world.
|
self : | Specifies the object instance that this function will act on. You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation. | |
mat : | The matrix to set as the observer. |
This function does not return any values. |
This is used to determine the LOD of physics objects. Currently, only a single observer is supported.
spawn_box ( self, pos, radius, actor, shape, material ) : stingray.ActorSpawns an improvised box at the specified position.
|
self : | Specifies the object instance that this function will act on. You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation. | |
pos : | The location where the new box is produced. | |
radius : | The half-extent of the box along each axis. | |
actor : | string? | The name of the actor template to use when constructing the box, if any. If specified, you must also specify the shape and material parameters. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
shape : | string? | The name of the shape template to use when constructing the box. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
material : | string? | The name of the material template to use when constructing the box. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
The newly spawned box. |
Most physics objects in a scene come from the units through the physics settings specified in the .physics file. However, sometimes it can be useful to spawn a completely improvised physics actor. This function spawns an improvised box.
Other related reference items
spawn_plane ( self, pos, normal, actor, shape, material ) : stingray.ActorSpawns a static plane with specified position and normal.
|
self : | Specifies the object instance that this function will act on. You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation. | |
pos : | The position of the plane. | |
normal : | The normal of the plane. | |
actor : | string? | The name of the actor template to use when constructing the plane, if any. If specified, you must also specify the shape and material parameters. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
shape : | string? | The name of the shape template to use when constructing the plane. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
material : | string? | The name of the material template to use when constructing the plane. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
The newly spawned plane. |
Most physics objects in a scene come from the units through the physics settings specified in the .physics file. However, sometimes it can be useful to spawn a completely improvised physics actor. This function spawns an improvised plane.
Other related reference items
spawn_sphere ( self, pos, radius, actor, shape, material ) : stingray.ActorSpawns an improvised sphere at specified position.
|
self : | Specifies the object instance that this function will act on. You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation. | |
pos : | The location where the new sphere is produced. | |
radius : | number | The radius of the sphere. |
actor : | string? | The name of the actor template to use when constructing the sphere, if any. If specified, you must also specify the shape and material parameters. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
shape : | string? | The name of the shape template to use when constructing the sphere. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
material : | string? | The name of the material template to use when constructing the sphere. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
The newly spawned sphere. |
Most physics objects in a scene come from the units through the physics settings specified in the .physics file. However, sometimes it can be useful to spawn a completely improvised physics actor. This function spawns an improvised sphere.
Other related reference items
wake_actors ( self, filter_id, min, max )Wakes all physics actors that collide with the specified collision filter and that intersect the axis-oriented bounding box defined by the specified minima and maxima.
|
self : | Specifies the object instance that this function will act on. You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation. | |
filter_id : | string | The id of the collision filter. |
min : | The minimum value of the vector. | |
max : | The maximum value of the vector. |
This function does not return any values. |
Other related reference items