This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Landscape Tool
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Body Class

Warning
The scope of applications for UnigineScript is limited to implementing materials-related logic (material expressions, scriptable materials, brush materials). Do not use UnigineScript as a language for application logic, please consider C#/C++ instead, as these APIs are the preferred ones. Availability of new Engine features in UnigineScript (beyond its scope of applications) is not guaranteed, as the current level of support assumes only fixing critical issues.

This class is used to simulate physical bodies that allow an object to participate in physical interactions. A body can have one or several collision shapes assigned and can be connected together with joints. To transform a body, one of the following functions can be used:

All of these functions take effect when physics calculations are over and updatePhysics() is performed. Only after that transformations of the body are applied to the rendered node. If a node needs to be transformed immediately after its physical body, flushTransform() is to be called.

The simulation of the body can be frozen (if a setFrozen flag is set).

You can set callbacks for a body to handle certain events:

  • setFrozenCallback() - to perform some actions when a body freezes.
  • setPositionCallback() - to perform some actions when a body changes its position.
  • setContactEnterCallback() - to perform some actions when a contact emerges (body starts touching another body or collidable surface).
  • setContactLeaveCallback() - to perform some actions when a contact ends (body stops touching another body or collidable surface).
  • setContactCallback() - to get all contacts of the body including new ones (enter) and the ending ones (leave). Leave contacts are removed after the callback execution stage, so this is the only point where you can still get them.

See Also#

  • The Creating and Attaching a Cloth usage example demonstrating how to create objects, assign bodies, and add shapes to them
  • A C++ API sample located in the <UnigineSDK>/source/samples/Api/Physics/BodyCallbacks folder
  • A C# API sample located in the <UnigineSDK>/source/csharp/samples/Api/Physics/BodyCallbacks folder
  • A set of UnigineScript API samples located in the <UnigineSDK>/data/samples/physics/ folder:
    • callbacks_00
    • callbacks_01
    • callbacks_02
  • The Handling Contacts on Collision usage example

Body Class

Members


Body createBody ( int type ) #

Creates a new body of the specified type.

Arguments

  • int type - Body type. One of the BODY_* values.

Return value

New created body instance.

Body createBody ( string type_name ) #

Creates a new body of the specified type.

Arguments

  • string type_name - Body type name.

Return value

New created body instance.

void setID ( int id ) #

Sets the unique ID for the body.

Arguments

  • int id - Unique ID.

int getID ( ) #

Returns the unique ID of the body.

Return value

Unique ID.

int getType ( ) #

Returns the type of the body.

Return value

One of the BODY_* pre-defined variables.

string getTypeName ( ) #

Returns the name of the body type.

Return value

Type name.

string getTypeName ( int type ) #

Returns the name of a body type with a given ID.

Arguments

  • int type - Body type ID. One of the BODY_* values.

Return value

Body type name.

void setObject ( bool update ) #

Sets an object, which the body approximates.

Arguments

  • bool update - Update flag: 1 to update the object after assigning the body (by default), 0 not to update right after body assignment.

getObject ( ) #

Returns the object, which is approximated with the body.

Return value

Approximated object.

void setEnabled ( int enable ) #

Enables or disables physical interactions with the body.

Arguments

  • int enable - 1 to enable physical interactions, 0 to disable them.

int isEnabled ( ) #

Returns a value indicating if physical interactions with the body are enabled.

Return value

1 if physical interactions with the body are enabled; otherwise, 0.

int isEnabledSelf ( ) #

Returns a value indicating if the body is enabled.

Return value

1 if the body is enabled; otherwise, 0.

void setFrozen ( int frozen ) #

Freezes or unfreezes the body. When a body is frozen, it is not simulated (though its contacts are still calculated), until a collision with a frozen body occurs or some force is applied.

Arguments

  • int frozen - 1 to freeze the object, 0 to unfreeze it.

int isFrozen ( ) #

Returns a value indicating if the body is frozen. When a body is frozen, it is not simulated (though its contacts are still calculated), until a collision with a frozen body occurs or some force is applied.

Return value

1 if the body is frozen; otherwise, 0.

void setImmovable ( int immovable ) #

Sets a value indicating if the body is immovable (static).

Arguments

  • int immovable - 1 if the body is immovable (static); otherwise, 0.

int isImmovable ( ) #

Return a value indicating if the body is immovable (static).

Return value

1 if the body is immovable (static); otherwise, 0.

void setGravity ( int gravity ) #

Sets a value indicating if gravity is affecting the body.

Arguments

  • int gravity - 1 if the body is affected by gravity; otherwise, 0.

int isGravity ( ) #

Returns a value indicating if gravity is affecting the body.

Return value

1 if the body is affected by gravity; otherwise, 0.

void setName ( string name ) #

Sets the name of the body.

Arguments

  • string name - Name of the body.

string getName ( ) #

Returns the name of the body.

Return value

Name of the body.

void setPhysicalMask ( int mask ) #

Sets the bit mask for interactions with physicals. Two objects interact, if they both have matching masks.

Arguments

  • int mask - Integer, each bit of which is a mask.

int getPhysicalMask ( ) #

Returns the bit mask for interactions with physicals. Two objects interact, if they both have matching masks.

Return value

Integer, each bit of which is a mask.

void setTransform ( Mat4 transform ) #

Sets a transformation matrix for the body (in world coordinates). This method resets body's linear and angular velocities to defaults, sets forces and torques to zeros, nullifies counted down frozen frames. It is called, for example, when the node is dragged to a new position in the editor.

Arguments

  • Mat4 transform - Transformation matrix. This matrix describes position, orientation and scale of the body.

Mat4 getTransform ( ) #

Returns the transformation matrix of the body (in world coordinates). This matrix describes position and orientation of the body.

Return value

Transformation matrix.

void setPreserveTransform ( Mat4 transform ) #

Sets a transformation matrix for the body (in world coordinates). This method safely preserves body's linear and angular velocities. It changes only body coordinates - all other body parameters stay the same.

Arguments

  • Mat4 transform - Transformation matrix. This matrix describes position, orientation and scale of the body.

void setVelocityTransform ( Mat4 transform ) #

Sets a transformation matrix (in world coordinates) and computes linear and angular velocities of the body depending on its trajectory from the current position to the specified one. The time used in calculations corresponds to physics ticks. It clears forces and torques to zeros and nullifies counted down frozen frames.

Arguments

  • Mat4 transform - Transformation matrix. This matrix describes position, orientation and scale of the body.

void flushTransform ( ) #

Forces to set the transformations of the body for the node.

void setPosition ( Vec3 pos ) #

Updates the body position (in world coordinates). Body's linear and angular velocities will be reset to 0.

Arguments

  • Vec3 pos - New position in the world coordinates.

Vec3 getPosition ( ) #

Returns the body position (in world coordinates).

Return value

The body position in the world coordinates.

void setRotation ( quat rot ) #

Updates the body rotation (in world coordinates).

Arguments

  • quat rot - New rotation in the world coordinates.

quat getRotation ( ) #

Returns the body rotation (in world coordinates).

Return value

The body rotation in the world coordinates.

void setDirection ( vec3 dir, vec3 up ) #

Updates the direction vector of the body (in world coordinates). By default, a direction vector points along -Z axis. This function changes its direction and reorients the body.

Arguments

  • vec3 dir - New direction vector in the world coordinates. The direction vector always has unit length.
  • vec3 up - New up vector in the world coordinates.

vec3 getDirection ( ) #

Returns the normalized direction vector of the body (in world coordinates). By default, a direction vector points along -Z axis. It always has an unit length.

Return value

Normalized direction vector in the world coordinates.

Body getParent ( ) #

Returns the parent of the body.

Return value

Parent body.

int isChild ( Body body ) #

Checks if a given body is a child of the body.

Arguments

  • Body body - Body to check.

Return value

1 if the provided body is a child; otherwise, 0.

int getNumChildren ( ) #

Returns the number of child bodies.

Return value

Number of children.

int findChild ( string name ) #

Searches for a child body with a given name.

Arguments

  • string name - Name of the child body.

Return value

Number of the child in the list of children, if it is found; otherwise, -1.

Body getChild ( int num ) #

Returns a given child body.

Arguments

  • int num - Child number.

Return value

Corresponding body.

void addShape ( Shape shape, mat4 transform ) #

Adds a shape to the list of shapes comprising the body.

Arguments

  • Shape shape - New shape to add.
  • mat4 transform - Shape transformation matrix (in the body's coordinate system).

void addShape ( Shape shape ) #

Adds a shape to the list of shapes comprising the body.

Arguments

  • Shape shape - New shape to add.

void clearShapes ( int destroy = 0 ) #

Clears all shapes from the body.

Arguments

  • int destroy - Flag indicating whether shapes are to be destroyed after removal: use 1 to destroy shapes after removal, or 0 if you plan to use them later. The default value is 0.

int isShape ( Shape shape ) #

Checks if a given shape belongs to the body.

Arguments

  • Shape shape - Shape to check.

Return value

1 if the shape belongs to the body; otherwise, 0.

int insertShape ( int pos, Shape shape ) #

Inserts a given shape at the specified position in the list of body's shapes.

Arguments

  • int pos - Position in the list at which the shape is to be inserted in the range from 0 to the number of shapes.
  • Shape shape - Shape to be inserted.

Return value

1 if a shape was successfully inserted; otherwise, 0.

int insertShape ( int pos, Shape shape, mat4 transform ) #

Inserts a given shape at the specified position in the list of body's shapes and sets the specified transformation for it.

Arguments

  • int pos - Position in the list at which the shape is to be inserted in the range from 0 to the number of shapes.
  • Shape shape - Shape to be inserted.
  • mat4 transform - Shape's transformation (in the body's coordinate system).

Return value

1 if a shape was successfully inserted; otherwise, 0.

int getNumShapes ( ) #

Returns the number of shapes comprising the body.

Return value

Number of shapes.

int findShape ( string name ) #

Searches for a shape with a given name.

Arguments

  • string name - Name of the shape.

Return value

Number of the shape in the list of shapes, if it is found; otherwise, -1.

Shape getShape ( int num ) #

Returns a given shape.

Arguments

  • int num - Shape number.

Return value

Corresponding shape object.

void setShapeTransform ( int num, mat4 transform ) #

Sets a transformation matrix for a given shape (in local coordinates). This matrix describes position and orientation of the shape.

Arguments

  • int num - Shape number.
  • mat4 transform - Transformation matrix (in the body's coordinate system).

mat4 getShapeTransform ( int num ) #

Returns the transformation matrix of a given shape (in local coordinates). This matrix describes position and orientation of the shape.

Arguments

  • int num - Shape number.

Return value

Transformation matrix.

void updateShapes ( ) #

Updates all shapes of the body.

void addJoint ( Joint joint ) #

Adds a joint to the body.

Arguments

  • Joint joint - New joint to add.

void removeJoint ( ) #

Removes a given joint from the body.

Arguments

    void insertJoint ( Joint joint, int num ) #

    Inserts a given joint at the specified position in the list of body's joints.

    Arguments

    • Joint joint - Joint to be inserted.
    • int num - Position in the list at which the joint is to be inserted in the range from 0 to the number of joints.

    int isJoint ( Joint joint ) #

    Checks if a given joint belongs to the body.

    Arguments

    • Joint joint - Joint to check.

    Return value

    1 if the joint belongs to the body; otherwise, 0.

    int getNumJoints ( ) #

    Returns the number of joints in the body.

    Return value

    Number of joints.

    int findJoint ( string name ) #

    Searches for a joint with a given name.

    Arguments

    • string name - Name of the joint.

    Return value

    Number of the joint in the list of joints, if it is found; otherwise, -1.

    Joint getJoint ( int num ) #

    Returns a given joint.

    Arguments

    • int num - Joint number.

    Return value

    Corresponding joint.

    getIntersection ( int mask, variable v ) #

    Performs tracing from the p0 point to the p1 point to find a body shape intersected by this line. Intersection is found only for objects with a matching intersection mask. On success ret_point and ret_normal shall contain information about intersection.

    Notice
    World space coordinates are used for this function.

    Depending on the variable passed as an argument, the result can be presented as a PhysicsIntersection or PhysicsIntersectionNormal class instance.

    Arguments

    • int mask - Intersection mask.
    • variable v - Variable defining which type of intersection object will be returned:
      • PhysicsIntersection intersectionPhysicsIntersection class instance containing intersection information (contact point coordinates).
      • PhysicsIntersectionNormal normalPhysicsIntersectionNormal class instance containing intersection information (contact point and normal coordinates).

    Return value

    First intersected shape, if found; otherwise, 0.

    int getNumContacts ( ) #

    Returns the total number of contacts in which the body participates. It includes internal (handled by the body) and external contacts (handled by other bodies).

    Return value

    Number of contacts.

    long getContactID ( int num ) #

    Returns the contact ID by the contact number.

    Arguments

    Return value

    Contact ID.

    int findContactByID ( long id ) #

    Returns the number of the contact by its ID.

    Arguments

    • long id - Contact ID.

    Return value

    Number of the contact with the specified ID if it exists, otherwise -1.

    int isContactInternal ( int num ) #

    Returns a value indicating whether the contact with the specified number is internal (handled by the body) or not (handled by another body). A contact can be handled by any of the bodies that participate in it. To which body a contact is assigned is random. If the contact is assigned to and handled by the body it is called an internal one, otherwise it is called external (handled by another body). The total number of contacts for the body includes all, internal and external ones. Iterating through internal contacts is much faster than through external ones, thus you might want a certain body to handle most of the contacts it participates in. This can be done for a rigid body by raising a priority for the body via the setHighPriorityContacts() method.

    Arguments

    Return value

    1 if the contact with the specified number is internal; otherwise 0.

    int isContactEnter ( int num ) #

    Returns a value indicating if the body has begun touching another body at the contact point with the specified number (the contact has just occurred).

    Arguments

    Return value

    1 if the body has begun touching another body at the contact point with the specified number (the contact has just occurred); otherwise 0.

    int isContactLeave ( int num ) #

    Returns a value indicating if the body has stopped touching another body at the contact point with the specified number.

    Arguments

    Return value

    1 if the body has stopped touching another body at the contact point with the specified number; otherwise 0.

    int isContactStay ( int num ) #

    Returns a value indicating if the body keeps touching another body at the contact point with the specified number (the contact lasts).

    Arguments

    Return value

    1 if the body keeps touching another body at the contact point with the specified number (the contact lasts); otherwise 0.

    Vec3 getContactPoint ( int num ) #

    Returns world coordinates of the contact point.

    Arguments

    Return value

    Contact point (in world coordinates).

    vec3 getContactNormal ( int num ) #

    Returns a normal of the contact point, in world coordinates.

    Arguments

    Return value

    Contact normal (in world coordinates).

    vec3 getContactVelocity ( int num ) #

    Returns relative velocity at the given contact point.

    Arguments

    Return value

    Velocity vector.

    float getContactImpulse ( int num ) #

    Returns the relative impulse at the given contact point.

    Arguments

    Return value

    Impulse value.

    float getContactTime ( int num ) #

    Returns the time when the given contact occurs. By CCD (for spheres or capsules), it returns the time starting from the current physics simulation tick to the moment when the calculated contact is bound to happen. By non-continuous collision detection, 0 is always returned.

    Arguments

    Return value

    Time of the calculated contact to happen, in seconds.

    float getContactDepth ( int num ) #

    Returns the depth by which the body penetrated with an obstacle by the given contact. This distance is measured along the contact normal.

    Arguments

    Return value

    Penetration depth, in units.

    float getContactFriction ( int num ) #

    Returns relative friction at the given contact point.

    Arguments

    Return value

    Friction value.

    float getContactRestitution ( int num ) #

    Returns relative restitution at the given contact point.

    Arguments

    Return value

    Restitution.

    Body getContactBody0 ( int num ) #

    Returns the first body participating in a given contact. This is not necessarily the current body.

    Arguments

    Return value

    First body.

    Body getContactBody1 ( int num ) #

    Returns the second body participating in a given contact. This is not necessarily the current body.

    Arguments

    Return value

    Second body.

    Shape getContactShape0 ( int num ) #

    Returns the first shape participating in a given contact. This shape does not necessarily belong to the current body.

    Arguments

    Return value

    First shape.

    Shape getContactShape1 ( int num ) #

    Returns the second shape participating in a given contact. This shape does not necessarily belong to the current body.

    Arguments

    Return value

    Second shape.

    Object getContactObject ( int num ) #

    Returns an object participating in the contact (used for collisions with non-physical object).

    Arguments

    Return value

    Object in contact.

    int getContactSurface ( int num ) #

    Returns the surface of the current object, which is in contact (used for collisions with non-physical object).

    Arguments

    Return value

    Surface number.

    void setFrozenCallback ( int func ) #

    Adds a callback function to be called when a given body freezes.

    The signature of the frozen callback function must be as follows:

    Source code (UnigineScript)
    void frozen_callback_function_name(Body body);

    You can set a callback function as follows:

    Source code (UnigineScript)
    setFrozenCallback("frozen_callback_function_name");
    Notice
    Physics-based callbacks are executed in the main tread, as they are mainly used for creation, destruction or modification of other objects.

    Example: Setting a body frozen callback function for a certain class:

    Source code (UnigineScript)
    class SomeClass
    {
    	// body for which a frozen callback function is to be set
    	Body body;
    
    	/*...*/
    
    	// callback function
    	void on_frozen(Body body)
    	{
    		// insert your code handling freezing here
    	}
    
    	void registerCallback()
    	{
    		// setting the on_frozen() function to handle freezing for the body
    		body.setFrozenCallback("SomeClass::on_frozen");
    	}
    	
    	/*...*/
    };

    Arguments

    • int func - Callback function name.

    void setPositionCallback ( int func ) #

    Adds a callback function to be called when a given body moves a certain distance (rotation is not taken into account).

    The signature of the position callback function must be as follows:

    Source code (UnigineScript)
    void position_callback_function_name(Body body);

    You can set a callback function as follows:

    Source code (UnigineScript)
    setPositionCallback("position_callback_function_name");
    Notice
    Physics-based callbacks are executed in the main tread, as they are mainly used for creation, destruction or modification of other objects.

    Example: Setting a body position callback function for a certain class:

    Source code (UnigineScript)
    class SomeClass
    {
    	// body for which a position callback function is to be set
    	Body body;
    
    	/*...*/
    
    	// callback function
    	void on_position(Body body)
    	{
    		// insert your code handling position changes here
    	}
    
    	void registerCallback()
    	{
    		// setting the on_position() function to handle position changes for the body
    		body.addPositionCallback("SomeClass::on_position");
    	}
    	
    	/*...*/
    };

    Arguments

    • int func - Callback function name.

    void setContactsCallback ( int func ) #

    Adds a callback function to be called after adding new contacts and before removing the ones that cease to exist. This callback can be used to get all contacts of the body including new ones (enter) and the ending ones (leave). Leave contacts are removed after the callback execution stage, so this is the only point where you can still get them. The signature of the contacts callback function must be one of the following:
    Source code (UnigineScript)
    contacts_callback_function_name(Body body);
    contacts_callback_function_name(Body body,int num); // num is the contact ID
    contacts_callback_function_name(Body body,int num,variable arg0); // num is the contact ID
    contacts_callback_function_name(Body body,int num,variable arg0,variable arg1); // num is the contact ID
    You can set a callback function as follows:
    Source code (UnigineScript)
    setContactsCallback("contacts_callback_function_name",arg0,arg1);
    This function contacts_callback_function_name() must have the following signature:
    Source code (UnigineScript)
    contacts_callback_function_name(Body body,int num,variable arg0,variable arg1);
    Notice
    Physics-based callbacks are executed in the main tread, as they are mainly used for creation, destruction or modification of other objects.

    Arguments

    • int func - Callback function name.

    void setContactEnterCallback ( int func ) #

    Adds a callback function to be called when a contact with the body emerges (the body begins touching another body). The signature of the callback function must be one of the following:
    Source code (UnigineScript)
    contact_callback_function_name(Body body);
    contact_callback_function_name(Body body,int num); // num is the contact ID
    contact_callback_function_name(Body body,int num,variable arg0); // num is the contact ID
    contact_callback_function_name(Body body,int num,variable arg0,variable arg1); // num is the contact ID
    You can set a callback function as follows:
    Source code (UnigineScript)
    setContactEnterCallback("contact_enter_callback_function_name",arg0,arg1);
    This function contact_enter_callback_function_name() must have the following signature:
    Source code (UnigineScript)
    contact_enter_callback_function_name(Body body,int num,variable arg0,variable arg1);
    Notice
    Physics-based callbacks are executed in the main tread, as they are mainly used for creation, destruction or modification of other objects.

    Arguments

    • int func - Callback function name.

    void setContactLeaveCallback ( int func ) #

    Adds a callback function to be called when a contact with the body ends (the body stops touching another body). The signature of the callback function must be one of the following:
    Source code (UnigineScript)
    contact_callback_function_name(Body body);
    contact_callback_function_name(Body body,int num); // num is the contact ID
    contact_callback_function_name(Body body,int num,variable arg0); // num is the contact ID
    contact_callback_function_name(Body body,int num,variable arg0,variable arg1); // num is the contact ID
    You can set a callback function as follows:
    Source code (UnigineScript)
    setContactLeaveCallback("contact_leave_callback_function_name",arg0,arg1);
    This function contact_leave_callback_function_name() must have the following signature:
    Source code (UnigineScript)
    contact_leave_callback_function_name(Body body,int num,variable arg0,variable arg1);
    Notice
    Physics-based callbacks are executed in the main tread, as they are mainly used for creation, destruction or modification of other objects.

    Arguments

    • int func - Callback function name.

    void renderContacts ( ) #

    Renders all contact points of the body including internal and external ones (handled by other bodies).
    Notice
    You should enable the engine visualizer via the show_visualizer 1 console command.

    void renderExternalContacts ( ) #

    Renders all external contacts of the body (handled by other bodies).
    Notice
    You should enable the engine visualizer via the show_visualizer 1 console command.

    void renderInternalContacts ( ) #

    Renders all internal contacts of the body (handled by it).
    Notice
    You should enable the engine visualizer via the show_visualizer 1 console command.

    void renderJoints ( ) #

    Renders joints to which the body is connected.
    Notice
    You should enable the engine visualizer via the show_visualizer 1 console command.

    void renderShapes ( ) #

    Renders shapes comprising the body.
    Notice
    You should enable the engine visualizer via the show_visualizer 1 console command.

    void renderVisualizer ( ) #

    Renders shapes, joints and contact points of the body.
    Notice
    You should enable the engine visualizer via the show_visualizer 1 console command.

    Body clone ( Object object ) #

    Clones the body and assigns a copy to a given object.

    Arguments

    • Object object - Object, to which the copy will be assigned.

    Return value

    Copy of the body.

    void swap ( Body body ) #

    Swaps the bodies saving the pointers.

    Arguments

    • Body body - Body to swap.

    int saveState ( Stream stream ) #

    Saves the state of a given body into a binary stream.

    Example using saveState() and restoreState() methods:

    Source code (UnigineScript)
    // set the body state
    body.setPosition(vec3(1, 1, 0));
    
    // save state
    Blob blob_state = new Blob();
    body.saveState(blob_state);
    
    // change state
    body.setPosition(vec3(0, 0, 0));
    
    // restore state
    blob_state.seekSet(0); // returning the carriage to the start of the blob
    body.restoreState(blob_state);

    Arguments

    • Stream stream - Stream to save body state data.

    Return value

    1 if the body state is successfully saved; otherwise, 0.

    int restoreState ( Stream stream ) #

    Restores the state of a given body from a binary stream.

    Example using saveState() and restoreState() methods:

    Source code (UnigineScript)
    // set the body state
    body.setPosition(vec3(1, 1, 0));
    
    // save state
    Blob blob_state = new Blob();
    body.saveState(blob_state);
    
    // change state
    body.setPosition(vec3(0, 0, 0));
    
    // restore state
    blob_state.seekSet(0); // returning the carriage to the start of the blob
    body.restoreState(blob_state);

    Arguments

    • Stream stream - Stream with saved body state data.

    Return value

    1 if the body state is successfully restored; otherwise, 0.
    Last update: 2021-12-13
    Build: ()