Skip to main content

VehicleMut

Struct VehicleMut 

Source
pub struct VehicleMut<'w, K: VehicleKind = WheeledVehicle> { /* private fields */ }
Expand description

Write access to one vehicle of kind K, borrowed mutably from its world.

Read the vehicle through PhysicsWorld::vehicle once this borrow ends.

The kind of the id selects the driver input: a wheeled vehicle takes a DriverInput, a tracked vehicle a TrackedDriverInput, and the other one does not compile:

ⓘ
use oxijolt::*;

fn drive(world: &mut PhysicsWorld, car: VehicleId) -> Result<(), VehicleError> {
    world.vehicle_mut(car)?.set_driver_input(TrackedDriverInput::default())
}
ⓘ
use oxijolt::*;

fn drive(world: &mut PhysicsWorld, tank: VehicleId<TrackedVehicle>) -> Result<(), VehicleError> {
    world.vehicle_mut(tank)?.set_driver_input(DriverInput::default())
}

Implementations§

Source§

impl<K: VehicleKind> VehicleMut<'_, K>

Source

pub fn set_gravity(&mut self, gravity: Vec3) -> Result<(), VehicleError>

Replaces the world’s gravity for this vehicle by gravity, m/s² (Jolt VehicleConstraint::OverrideGravity). It must be finite and at most limits::MAX_ACCELERATION long. The chassis is a dynamic body, so its mass is at most limits::MAX_MASS and the force Jolt derives from the override stays finite.

On every step while the chassis is awake, Jolt sets the chassis’ gravity factor to 0 and adds the force gravity / inverse mass at its centre of mass; a sleeping chassis gets no force. The opposite of gravity also becomes the world up of the pitch and roll limit; a zero gravity keeps the last world up, which a restore does not undo (see WorldState). The override stays until it is set again; there is no reset, because Jolt’s reset writes gravity factor 1 to the chassis. For radial gravity, set it every tick. Not part of WorldState: PhysicsWorld::restore_state does not undo it.

Source

pub fn set_max_pitch_roll_angle( &mut self, radians: f32, ) -> Result<(), VehicleError>

Sets the largest pitch and roll angle, radians in [0, π]; π turns the limit off. See WheeledVehicleSettings::max_pitch_roll_angle. Not part of WorldState: PhysicsWorld::restore_state does not undo it.

Source

pub fn set_collision_tester( &mut self, tester: VehicleCollisionTester, ) -> Result<(), VehicleError>

Replaces the collision tester, checked against this vehicle’s wheels as at creation. The next step tests the wheels with it. Not part of WorldState: PhysicsWorld::restore_state does not undo it.

Source§

impl VehicleMut<'_, WheeledVehicle>

Source

pub fn set_driver_input( &mut self, input: DriverInput, ) -> Result<(), VehicleError>

Sets what the driver asks for the next steps; see DriverInput for the ranges.

Source§

impl VehicleMut<'_, Motorcycle>

Source

pub fn set_driver_input( &mut self, input: DriverInput, ) -> Result<(), VehicleError>

Sets what the driver asks for the next steps; see DriverInput for the ranges.

Source§

impl VehicleMut<'_, TrackedVehicle>

Source

pub fn set_driver_input( &mut self, input: TrackedDriverInput, ) -> Result<(), VehicleError>

Sets what the driver asks for the next steps; see TrackedDriverInput for the ranges. A refused input changes nothing.

Trait Implementations§

Source§

impl<K: VehicleKind> Debug for VehicleMut<'_, K>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'w, K = WheeledVehicle> !Send for VehicleMut<'w, K>

§

impl<'w, K = WheeledVehicle> !Sync for VehicleMut<'w, K>

§

impl<'w, K = WheeledVehicle> !UnwindSafe for VehicleMut<'w, K>

§

impl<'w, K> Freeze for VehicleMut<'w, K>
where PhantomData<fn() -> K>: Freeze,

§

impl<'w, K> RefUnwindSafe for VehicleMut<'w, K>
where PhantomData<fn() -> K>: RefUnwindSafe,

§

impl<'w, K> Unpin for VehicleMut<'w, K>
where PhantomData<fn() -> K>: Unpin,

§

impl<'w, K> UnsafeUnpin for VehicleMut<'w, K>
where PhantomData<fn() -> K>: UnsafeUnpin,

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> 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, 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, !>

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.