Struct ark_api::world::Physics

source ·
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§

source§

impl Physics

source

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.

source

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.

source

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.

source

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

source

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.

source

pub fn density(&self) -> ValueAccessorReadWrite<f32>

Returns a ValueAccessor for the density of the entity.

Only used if the physics body is dynamic and non-kinematic.

Note: Density is in kg/m3, so a value of 1000.0 is appropriate for water, maybe 700 for wood, 8000 for steel.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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).

source

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.

source

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.

source

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.

source

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.

source

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.

source

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).

source

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.

source

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!

source

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!

source

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!

source

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!

source

pub fn linear_damping(&self) -> ValueAccessorReadWrite<f32>

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

source

pub fn angular_damping(&self) -> ValueAccessorReadWrite<f32>

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

source

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.

source

pub fn solver_position_iterations(&self) -> ValueAccessorReadWrite<u64>

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

source

pub fn solver_velocity_iterations(&self) -> ValueAccessorReadWrite<u64>

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

source

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.

source

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.

source

pub fn non_uniform_scale(&self) -> ValueAccessorReadWriteAnimate<Vec3>

Returns a ValueAccessor for the non-uniform scale applied to the physics shape.

Used to set/get the scale.

source

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.

source

pub fn triggers(&self) -> Option<Vec<OnTrigger>>

Returns a Vec of trigger messages for this entity.

source

pub fn in_contact_with(&self, other: Entity) -> bool

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

source

pub fn contact_entities(&self) -> Vec<Entity>

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

Trait Implementations§

source§

impl ComponentTrait for Physics

source§

fn get_type() -> ComponentType

The type of the component, as a ComponentType enum.
source§

fn from_entity(handle: Entity) -> Self

Adopt an Entity, wrap in a component struct.
source§

fn entity(&self) -> Entity

Get the entity that the component belongs to.
source§

impl Debug for Physics

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.