logo
pub struct Physics { /* private fields */ }
Expand description

Physics component.

Use to turn on and off physics processing and to set up physical properties and movement of an object.

Implementations

Turns on physics processing for this mesh, as a dynamic entity.

The layer set in Layer component, if any, will be used for collisions.

It will also remove the transform parent, if set. Note: Density is in kg/m3, so a value of 1000.0 is appropriate for water, maybe 700 for wood, 8000 for steel.

Enables physics processing, as a static entity which will not move as a result of physics.

The layer set in Layer component, if any, will be used for collisions.

Can use mesh collision. Suitable for environments.

Enables physics processing, as a kinematic entity which can be explicitly moved.

The layer set in Layer component, if any, will be used for collisions.

Kinematic entities are also regarded as dynamic, but do not disable the use of directly setting the position and rotation of the Transform component. Parenting is allowed. Suitable for stuff like elevators, moving platforms etc.

Checks if physics processing is enabled for this entity

This is enabled by default but can be disabled with Physics::disable

Disables physics processing for this entity.

Note: If you used dynamic physics, any transform parent set will have been removed so you need to restore it (and whatever parent relative transform you had) yourself.

Applies a physics force or torque to the center of an entity.

This does nothing unless Physics::enable has been called for this entity.

To instantly move a physics object, use add_force with force_type set to Forcetype::Teleport and force_mode set to ForceMode::Force.

Simplified wrapper for EntityMessenger::physics_force_at_request.

Applies a physics force or torque at a point of an entity.

This does nothing unless Physics::enable has been called for this entity.

Torques ignore the pos parameter, but work in either force_space. To instantly move a physics object, use add_force with force_type set to Forcetype::Teleport and force_mode set to ForceMode::Force. To replicate add_force, set force_space to Space::World, pos_space to Space::Local, and pos to Vec3::ZERO.

Wraps EntityMessenger::physics_force_request_at.

Lets you check the current rigid body mode of this entity.

Note that it will not return a value until a frame has passed since the initial creation.

Returns a ValueAccessor for the current world-space linear velocity of the entity.

Writing is possible but not recommended, it’s better to use forces whenever possible.

Returns a ValueAccessor for the current world-space angular velocity of the entity.

The returned vector is pointing along the axis of rotation, with its length representing the speed of rotation.

Writing is possible but not recommended, it’s better to use forces/torques whenever possible.

Returns a ValueAccessor for the dynamic friction of the entity.

Range 0..1. Default: 0.5.

Dynamic friction is applied when the two touching objects are in motion relative to each other. 1.0 means that the friction force is equal to the normal force, but there are materials with higher friction coefficients. This will currently only be applied the next time you enable physics on the entity - it can’t be dynamically updated yet. In simulation, the friction used is a combination of the friction properties of the two touching entities.

Returns a ValueAccessor for the static friction of the entity.

Range is 0 and upwards. Default: 0.5.

Static friction is applied when the two touching objects are still relative to each other. 1.0 means that the friction force is equal to the normal force, but there are materials with higher friction coefficients. This will currently only be applied the next time you enable physics on the entity - it can’t be dynamically updated yet. In simulation, the friction used is a combination of the friction properties of the two touching entities.

Returns a ValueAccessor for the restitution (bounciness) of the entity.

Range 0..1. Default: 0.6.

This will currently only be applied the next time you enable physics on the entity - it can’t be dynamically updated yet. Note that the actual restitution is a combination of the restitution of the two touching objects. So if you want a ball to bounce indefinitely, both the ball and the ground needs to have restitution 1.0 (not recommended, does not look realistic).

Returns a ValueAccessor for the create_sleeping flag of the entity.

If this flag is set before enable_dynamic is called, the rigid body will be created in a sleeping state.

Returns a ValueAccessor for the sleeping flag of the entity.

If this flag is set before enable_dynamic is called, it will not affect the rigid body. Only applies to dynamic rigid bodies.

Returns a ValueAccessor for the sleep_threshold flag of the entity.

If this value is set before enable_dynamic is called, it will not affect the rigid body. Only applies to dynamic rigid bodies.

Returns a ValueAccessor for the gravity_enabled flag of the entity.

If this flag is set to false before enable_dynamic is called, global gravity does not affect the rigid body. Only applies to dynamic rigid bodies.

Returns a ValueAccessor for the collision_events_mask of the entity.

Setups which collisions (layers) against this entity should generate events, Defaults to 0, but if set to 0 will be set to !0u64 on the first call to EntityMessenger::listen_collisions, which means that all collisions will generate messages. Note: It is a bit mask of Layer bits. Setup which layer an entity belongs to by adding a Layer component and set its layer bits.

Returns a ValueAccessor for the DynamicLockFlags of the entity.

Used to set/get the flags. Can be used to lock a dynamic rigid body. Both its translation (Linear) and rotation (Angular).

Returns a ValueAccessor for the compound physics shape of the physics component. Will only be used when the physics component is enabled.

Returns a ValueAccessor for the computed mass of the physics component.

NOTE: Cannot be accessed until you have called enable_dynamic!

Returns a ValueAccessor for the computed center of mass of the physics component.

NOTE: Cannot be accessed until you have called enable_dynamic!

Returns a ValueAccessor for the rotation of the mass space specified by the center_of_mass. Together they set up the space in which the inertia tensor is specified.

NOTE: Cannot be accessed until you have called enable_dynamic!

Returns a ValueAccessor for the diagonal inertia tensor in “mass space”

NOTE: Cannot be accessed until you have called enable_dynamic!

Returns a ValueAccessor for the linear damping coefficient. 0 means no damping.

Returns a ValueAccessor for the angular damping coefficient. 0 means no damping.

Returns a ValueAccessor for the trigger_volume property.

A trigger shape can send collision messages, but doesn’t physically collide with things.

The number of iterations the solver will run to try to solve positions. Default is 4.

The number of iterations the solver will run to try to solve velocity. Default is 1.

The friction combine mode of the material of this entity. Default is Average.

Note: The actual combine mode is the max of the combine modes of the two entities touching! This means that Max > Multiply > Min > Average in terms of priority.

The restitution combine mode of the material of this entity. Default is Average.

Note: The actual combine mode is the max of the combine modes of the two entities touching! This means that Max > Multiply > Min > Average in terms of priority.

Returns a Vec of collision messages for this entity.

If this entity hasn’t been setup to listen for collisions it will be.

Returns a Vec of trigger messages for this entity.

Returns whether this entity is currently physically in contact with a specific other entity.

Returns a list of other entities this entity is currently in contact with.

Trait Implementations

The type of the component, as a ComponentType enum.

Adopt an Entity, wrap in a component struct.

Get the entity that the component belongs to.

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.