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
sourceimpl Physics
impl Physics
sourcepub fn enable_dynamic(&self, density: f32, shape: PhysicsShape)
pub fn enable_dynamic(&self, density: f32, shape: PhysicsShape)
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.
sourcepub fn enable_static(&self, shape: PhysicsShape)
pub fn enable_static(&self, shape: PhysicsShape)
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.
sourcepub fn enable_kinematic(&self, shape: PhysicsShape)
pub fn enable_kinematic(&self, shape: PhysicsShape)
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.
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Checks if physics processing is enabled for this entity
This is enabled by default but can be disabled with Physics::disable
sourcepub fn disable(&self)
pub fn disable(&self)
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.
sourcepub fn add_force(&self, force_type: ForceType, force_mode: ForceMode, vector: Vec3)
pub fn add_force(&self, force_type: ForceType, force_mode: ForceMode, vector: Vec3)
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
.
sourcepub fn add_force_at(
&self,
force_type: ForceType,
force_mode: ForceMode,
force_space: Space,
pos_space: Space,
vector: Vec3,
pos: Vec3
)
pub fn add_force_at(
&self,
force_type: ForceType,
force_mode: ForceMode,
force_space: Space,
pos_space: Space,
vector: Vec3,
pos: Vec3
)
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
.
sourcepub fn rigid_body_mode(&self) -> ValueAccessorRead<RigidBodyMode>
pub fn rigid_body_mode(&self) -> ValueAccessorRead<RigidBodyMode>
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.
sourcepub fn velocity(&self) -> ValueAccessorReadWrite<Vec3>
pub fn velocity(&self) -> ValueAccessorReadWrite<Vec3>
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.
sourcepub fn angular_velocity(&self) -> ValueAccessorReadWrite<Vec3>
pub fn angular_velocity(&self) -> ValueAccessorReadWrite<Vec3>
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.
sourcepub fn dynamic_friction(&self) -> ValueAccessorReadWrite<f32>
pub fn dynamic_friction(&self) -> ValueAccessorReadWrite<f32>
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.
sourcepub fn static_friction(&self) -> ValueAccessorReadWrite<f32>
pub fn static_friction(&self) -> ValueAccessorReadWrite<f32>
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.
sourcepub fn restitution(&self) -> ValueAccessorReadWrite<f32>
pub fn restitution(&self) -> ValueAccessorReadWrite<f32>
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).
sourcepub fn create_sleeping(&self) -> ValueAccessorReadWrite<bool>
pub fn create_sleeping(&self) -> ValueAccessorReadWrite<bool>
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.
sourcepub fn sleeping(&self) -> ValueAccessorReadWrite<bool>
pub fn sleeping(&self) -> ValueAccessorReadWrite<bool>
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.
sourcepub fn sleep_threshold(&self) -> ValueAccessorReadWrite<f32>
pub fn sleep_threshold(&self) -> ValueAccessorReadWrite<f32>
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.
sourcepub fn gravity_enabled(&self) -> ValueAccessorReadWrite<bool>
pub fn gravity_enabled(&self) -> ValueAccessorReadWrite<bool>
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.
sourcepub fn collision_events_mask(&self) -> ValueAccessorReadWrite<u64>
pub fn collision_events_mask(&self) -> ValueAccessorReadWrite<u64>
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.
sourcepub fn dynamic_lock_flags(&self) -> ValueAccessorReadWrite<DynamicLockFlags>
pub fn dynamic_lock_flags(&self) -> ValueAccessorReadWrite<DynamicLockFlags>
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).
sourcepub fn compound_shape(&self) -> ValueAccessorDataReadWrite<CompoundPhysicsShape>
pub fn compound_shape(&self) -> ValueAccessorDataReadWrite<CompoundPhysicsShape>
Returns a ValueAccessor
for the compound physics shape of the physics component. Will only be used when the physics component is enabled.
sourcepub fn mass(&self) -> ValueAccessorReadWrite<f32>
pub fn mass(&self) -> ValueAccessorReadWrite<f32>
Returns a ValueAccessor
for the computed mass of the physics component.
NOTE: Cannot be accessed until you have called enable_dynamic
!
sourcepub fn center_of_mass(&self) -> ValueAccessorReadWrite<Vec3>
pub fn center_of_mass(&self) -> ValueAccessorReadWrite<Vec3>
Returns a ValueAccessor
for the computed center of mass of the physics component.
NOTE: Cannot be accessed until you have called enable_dynamic
!
sourcepub fn mass_rotation(&self) -> ValueAccessorReadWrite<Quat>
pub fn mass_rotation(&self) -> ValueAccessorReadWrite<Quat>
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
!
sourcepub fn inertia_tensor(&self) -> ValueAccessorReadWrite<Vec3>
pub fn inertia_tensor(&self) -> ValueAccessorReadWrite<Vec3>
Returns a ValueAccessor
for the diagonal inertia tensor in “mass space”
NOTE: Cannot be accessed until you have called enable_dynamic
!
sourcepub fn linear_damping(&self) -> ValueAccessorReadWrite<f32>
pub fn linear_damping(&self) -> ValueAccessorReadWrite<f32>
Returns a ValueAccessor
for the linear damping coefficient. 0 means no damping.
sourcepub fn angular_damping(&self) -> ValueAccessorReadWrite<f32>
pub fn angular_damping(&self) -> ValueAccessorReadWrite<f32>
Returns a ValueAccessor
for the angular damping coefficient. 0 means no damping.
sourcepub fn trigger_volume(&self) -> ValueAccessorReadWrite<bool>
pub fn trigger_volume(&self) -> ValueAccessorReadWrite<bool>
Returns a ValueAccessor
for the trigger_volume property.
A trigger shape can send collision messages, but doesn’t physically collide with things.
sourcepub fn solver_position_iterations(&self) -> ValueAccessorReadWrite<u64>
pub fn solver_position_iterations(&self) -> ValueAccessorReadWrite<u64>
The number of iterations the solver will run to try to solve positions. Default is 4.
sourcepub fn solver_velocity_iterations(&self) -> ValueAccessorReadWrite<u64>
pub fn solver_velocity_iterations(&self) -> ValueAccessorReadWrite<u64>
The number of iterations the solver will run to try to solve velocity. Default is 1.
sourcepub fn friction_combine_mode(&self) -> ValueAccessorReadWrite<CombineMode>
pub fn friction_combine_mode(&self) -> ValueAccessorReadWrite<CombineMode>
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.
sourcepub fn restitution_combine_mode(&self) -> ValueAccessorReadWrite<CombineMode>
pub fn restitution_combine_mode(&self) -> ValueAccessorReadWrite<CombineMode>
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.
sourcepub fn collisions(&self) -> Option<Vec<OnCollision>>
pub fn collisions(&self) -> Option<Vec<OnCollision>>
Returns a Vec of collision messages for this entity.
If this entity hasn’t been setup to listen for collisions it will be.
sourcepub fn triggers(&self) -> Option<Vec<OnTrigger>>
pub fn triggers(&self) -> Option<Vec<OnTrigger>>
Returns a Vec of trigger messages for this entity.
sourcepub fn in_contact_with(&self, other: Entity) -> bool
pub fn in_contact_with(&self, other: Entity) -> bool
Returns whether this entity is currently physically in contact with a specific other entity.
sourcepub fn contact_entities(&self) -> Vec<Entity>
pub fn contact_entities(&self) -> Vec<Entity>
Returns a list of other entities this entity is currently in contact with.
Trait Implementations
sourceimpl ComponentTrait for Physics
impl ComponentTrait for Physics
sourcefn get_type() -> ComponentType
fn get_type() -> ComponentType
The type of the component, as a ComponentType
enum.
sourcefn from_entity(handle: Entity) -> Self
fn from_entity(handle: Entity) -> Self
Adopt an Entity
, wrap in a component struct.
Auto Trait Implementations
impl RefUnwindSafe for Physics
impl Send for Physics
impl Sync for Physics
impl Unpin for Physics
impl UnwindSafe for Physics
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more