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>
impl<K: VehicleKind> VehicleMut<'_, K>
Sourcepub fn set_gravity(&mut self, gravity: Vec3) -> Result<(), VehicleError>
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.
Sourcepub fn set_max_pitch_roll_angle(
&mut self,
radians: f32,
) -> Result<(), VehicleError>
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.
Sourcepub fn set_collision_tester(
&mut self,
tester: VehicleCollisionTester,
) -> Result<(), VehicleError>
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>
impl VehicleMut<'_, WheeledVehicle>
Sourcepub fn set_driver_input(
&mut self,
input: DriverInput,
) -> Result<(), VehicleError>
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>
impl VehicleMut<'_, Motorcycle>
Sourcepub fn set_driver_input(
&mut self,
input: DriverInput,
) -> Result<(), VehicleError>
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>
impl VehicleMut<'_, TrackedVehicle>
Sourcepub fn set_driver_input(
&mut self,
input: TrackedDriverInput,
) -> Result<(), VehicleError>
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.