pub struct PhysicsWorld {
pub gravity: Vector<f32>,
/* private fields */
}Fields§
§gravity: Vector<f32>Implementations§
Source§impl PhysicsWorld
impl PhysicsWorld
pub fn new() -> Self
Sourcepub fn add_static_body(
&mut self,
id: NodeId,
position: (f32, f32),
rotation: f32,
)
pub fn add_static_body( &mut self, id: NodeId, position: (f32, f32), rotation: f32, )
Add a StaticBody2D to the physics world.
Sourcepub fn add_character_body(
&mut self,
id: NodeId,
position: (f32, f32),
rotation: f32,
)
pub fn add_character_body( &mut self, id: NodeId, position: (f32, f32), rotation: f32, )
Add a CharacterBody2D (kinematic position-based) to the physics world.
Sourcepub fn add_rigid_body(
&mut self,
id: NodeId,
position: (f32, f32),
rotation: f32,
mass: f32,
gravity_scale: f32,
lock_rotation: bool,
)
pub fn add_rigid_body( &mut self, id: NodeId, position: (f32, f32), rotation: f32, mass: f32, gravity_scale: f32, lock_rotation: bool, )
Add a RigidBody2D (dynamic) to the physics world.
Sourcepub fn add_area(&mut self, id: NodeId, position: (f32, f32), rotation: f32)
pub fn add_area(&mut self, id: NodeId, position: (f32, f32), rotation: f32)
Add an Area2D to the physics world.
Sourcepub fn attach_shape(
&mut self,
body_id: &NodeId,
shape_node_id: NodeId,
config: ShapeConfig,
offset: (f32, f32),
rotation: f32,
is_sensor: bool,
collision_layer: u32,
collision_mask: u32,
friction: f32,
restitution: f32,
)
pub fn attach_shape( &mut self, body_id: &NodeId, shape_node_id: NodeId, config: ShapeConfig, offset: (f32, f32), rotation: f32, is_sensor: bool, collision_layer: u32, collision_mask: u32, friction: f32, restitution: f32, )
Attach a CollisionShape2D collider to a parent body or area.
Sourcepub fn remove_node(&mut self, id: &NodeId)
pub fn remove_node(&mut self, id: &NodeId)
Remove a node (body or shape) from the physics world.
Sourcepub fn move_and_slide(
&mut self,
character_id: &NodeId,
desired_velocity: (f32, f32),
dt: f32,
up_direction: (f32, f32),
) -> CharacterMoveResult
pub fn move_and_slide( &mut self, character_id: &NodeId, desired_velocity: (f32, f32), dt: f32, up_direction: (f32, f32), ) -> CharacterMoveResult
Execute move_and_slide for a CharacterBody2D.
Sourcepub fn apply_impulse(&mut self, id: &NodeId, impulse: (f32, f32))
pub fn apply_impulse(&mut self, id: &NodeId, impulse: (f32, f32))
Apply an impulse to a RigidBody2D.
Sourcepub fn apply_force(&mut self, id: &NodeId, force: (f32, f32))
pub fn apply_force(&mut self, id: &NodeId, force: (f32, f32))
Apply a continuous force to a RigidBody2D.
pub fn is_rigid_body(&self, id: &NodeId) -> bool
Sourcepub fn get_body_position(&self, id: &NodeId) -> Option<(f64, f64)>
pub fn get_body_position(&self, id: &NodeId) -> Option<(f64, f64)>
Retrieve the current global position of a body.
Sourcepub fn set_body_position(&mut self, id: &NodeId, pos: (f64, f64))
pub fn set_body_position(&mut self, id: &NodeId, pos: (f64, f64))
Set the position of a body.
Sourcepub fn get_body_rotation(&self, id: &NodeId) -> Option<f64>
pub fn get_body_rotation(&self, id: &NodeId) -> Option<f64>
Retrieve the current rotation of a body.
Sourcepub fn raycast(
&self,
from: (f32, f32),
to: (f32, f32),
mask: u32,
) -> Option<RaycastHit>
pub fn raycast( &self, from: (f32, f32), to: (f32, f32), mask: u32, ) -> Option<RaycastHit>
Perform a 2D raycast query.
Sourcepub fn drain_events(&mut self) -> Vec<PhysicsEvent>
pub fn drain_events(&mut self) -> Vec<PhysicsEvent>
Drain queued collision events (body/area enter and exit).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for PhysicsWorld
impl !RefUnwindSafe for PhysicsWorld
impl !UnwindSafe for PhysicsWorld
impl Send for PhysicsWorld
impl Sync for PhysicsWorld
impl Unpin for PhysicsWorld
impl UnsafeUnpin for PhysicsWorld
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.