Skip to main content

PhysicsJoint

Struct PhysicsJoint 

Source
pub struct PhysicsJoint {
    pub asset_id: AssetId,
    pub kind: String,
    pub body_a: Option<AssetId>,
    pub body_b: Option<AssetId>,
    pub anchor_a: [f32; 3],
    pub anchor_b: [f32; 3],
    pub axis: [f32; 3],
    pub limits_enabled: bool,
    pub limits: [f32; 2],
    pub motor_target_velocity: f32,
    pub motor_max_force: f32,
}
Expand description

A physics constraint connecting two Props that own a collider.

The joint pins anchor_a on body_a to anchor_b on body_b and locks the relative motion of the two bodies according to its kind. Anchors are in each body’s local frame: [0, 0, 0] is the body’s own pivot.

To anchor a body to “the world” (no second prop), leave body_b empty: a hidden static anchor is created at anchor_b (interpreted as world space in that case) and the body joints to it. This is the pendulum / lamp / trapeze pattern.

axis only applies to revolute and prismatic: it is the single free axis (rotation or translation) in each body’s local frame. The vector is normalised on load; a zero axis falls back to [0, 1, 0].

limits_enabled clamps the free axis: angle in degrees for revolute, distance in world units for prismatic. motor_target_velocity and motor_max_force drive the free axis when motor_max_force > 0; the velocity is in degrees/sec for revolute, units/sec for prismatic.

PhysicsJoint {
    kind: "revolute".into(),
    anchor_a: [0.0, 2.0, 0.0],
    anchor_b: [0.0, 5.0, 0.0],
    axis: [0.0, 0.0, 1.0],
    ..Default::default()
};

Fields§

§asset_id: AssetId

Asset identity; injected via inject_name. Not part of args.

§kind: String

Constraint shape; defaults to “fixed”.

§body_a: Option<AssetId>

First body: a Prop name. Required.

§body_b: Option<AssetId>

Second body: a Prop name. Empty means “world anchor”, in which case anchor_b is interpreted as a world-space position.

§anchor_a: [f32; 3]

Attach point in body_a’s local frame.

§anchor_b: [f32; 3]

Attach point in body_b’s local frame (or world space if body_b is empty).

§axis: [f32; 3]

Free axis for revolute/prismatic, in each body’s local frame.

§limits_enabled: bool

Whether the limits clamp is enforced.

§limits: [f32; 2]

[min, max] clamp on the free axis: degrees for revolute, world units for prismatic. Ignored unless limits_enabled is true.

§motor_target_velocity: f32

Motor target velocity: degrees/sec for revolute, world units/sec for prismatic. Ignored unless motor_max_force > 0.

§motor_max_force: f32

Motor force budget. The motor is inactive when this is 0.

Implementations§

Source§

impl PhysicsJoint

Source

pub fn parsed_kind(&self) -> PhysicsJointKind

Parse kind; falls back to Fixed for unrecognised values so a typo degrades safely. Cross-reference validation flags bad kinds explicitly.

Trait Implementations§

Source§

impl Clone for PhysicsJoint

Source§

fn clone(&self) -> PhysicsJoint

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Component for PhysicsJoint

Source§

const NAME: &'static str = "PhysicsJoint"

The registry name a world authors this component under.
Source§

fn inject_name(&mut self, id: AssetId)

Called after construction to inject the asset’s identity from the blob def. Only meaningful for components that look themselves up by id at runtime. The default implementation does nothing.
Source§

fn from_baked(bytes: &[u8]) -> Result<Self, CnResult>

Reconstruct this component from a blob record, whose bytes are the serialized runtime component (cook already ran the asset -> component translation). The default rejects: runtime-only components are never stored in a blob, so only loadable types provide an implementation.
Source§

fn inject_locator(&mut self, _locator: PayloadLocator)

Called after construction to inject the payload locator from the blob def. Only meaningful for components with a compiled payload. The default implementation does nothing (correct for most components).
Source§

impl ComponentSlot for PhysicsJoint

Source§

const DISCRIMINANT: u8

The component type’s stable id, used as its ComponentId.
Source§

fn slot(s: &ComponentStorage) -> &Column<Self>

Borrow this type’s column out of the storage.
Source§

fn slot_mut(s: &mut ComponentStorage) -> &mut Column<Self>

Mutably borrow this type’s column out of the storage.
Source§

impl Debug for PhysicsJoint

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for PhysicsJoint

Source§

fn default() -> PhysicsJoint

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for PhysicsJoint

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<PhysicsJoint, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<PhysicsJoint> for ComponentAsset

Source§

fn from(c: PhysicsJoint) -> Self

Converts to this type from the input type.
Source§

impl RuntimeComponent for PhysicsJoint

Source§

impl Serialize for PhysicsJoint

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.