[−][src]Struct gdnative_bindings::KinematicBody2D
core class KinematicBody2D
inherits PhysicsBody2D
(unsafe).
Official documentation
See the documentation of this class in the Godot engine's official documentation.
Memory management
Non reference counted objects such as the ones of this type are usually owned by the engine.
KinematicBody2D
is a reference-only type. Persistent references can
only exist in the unsafe Ref<KinematicBody2D>
form.
In the cases where Rust code owns an object of this type, for example if the object was just
created on the Rust side and not passed to the engine yet, ownership should be either given
to the engine or the object must be manually destroyed using Ref::free
, or Ref::queue_free
if it is a Node
.
Class hierarchy
KinematicBody2D inherits methods from:
Safety
All types in the Godot API have "interior mutability" in Rust parlance.
To enforce that the official thread-safety guidelines are
followed, the typestate pattern is used in the Ref
and TRef
smart pointers,
and the Instance
API. The typestate Access
in these types tracks whether the
access is unique, shared, or exclusive to the current thread. For more information,
see the type-level documentation on Ref
.
Implementations
impl KinematicBody2D
[src]
pub fn new() -> Ref<Self, Unique>
[src]
Creates a new instance of this object.
Because this type is not reference counted, the lifetime of the returned object is not automatically managed.
Immediately after creation, the object is owned by the caller, and can be
passed to the engine (in which case the engine will be responsible for
destroying the object) or destroyed manually using Ref::free
, or preferably
Ref::queue_free
if it is a Node
.
pub fn get_floor_normal(&self) -> Vector2
[src]
Returns the surface normal of the floor at the last collision point. Only valid after calling [method move_and_slide] or [method move_and_slide_with_snap] and when [method is_on_floor] returns [code]true[/code].
pub fn get_floor_velocity(&self) -> Vector2
[src]
Returns the linear velocity of the floor at the last collision point. Only valid after calling [method move_and_slide] or [method move_and_slide_with_snap] and when [method is_on_floor] returns [code]true[/code].
pub fn safe_margin(&self) -> f64
[src]
If the body is at least this close to another body, this body will consider them to be colliding.
pub fn get_slide_collision(
&self,
slide_idx: i64
) -> Option<Ref<KinematicCollision2D, Shared>>
[src]
&self,
slide_idx: i64
) -> Option<Ref<KinematicCollision2D, Shared>>
Returns a [KinematicCollision2D], which contains information about a collision that occurred during the last [method move_and_slide] call. Since the body can collide several times in a single call to [method move_and_slide], you must specify the index of the collision in the range 0 to ([method get_slide_count] - 1).
[b]Example usage:[/b]
[codeblock]
for i in get_slide_count():
var collision = get_slide_collision(i)
print("Collided with: ", collision.collider.name)
[/codeblock]
pub fn get_slide_count(&self) -> i64
[src]
Returns the number of times the body collided and changed direction during the last call to [method move_and_slide].
pub fn is_on_ceiling(&self) -> bool
[src]
Returns [code]true[/code] if the body is on the ceiling. Only updates when calling [method move_and_slide].
pub fn is_on_floor(&self) -> bool
[src]
Returns [code]true[/code] if the body is on the floor. Only updates when calling [method move_and_slide].
pub fn is_on_wall(&self) -> bool
[src]
Returns [code]true[/code] if the body is on a wall. Only updates when calling [method move_and_slide].
pub fn is_sync_to_physics_enabled(&self) -> bool
[src]
If [code]true[/code], the body's movement will be synchronized to the physics frame. This is useful when animating movement via [AnimationPlayer], for example on moving platforms. Do [b]not[/b] use together with [method move_and_slide] or [method move_and_collide] functions.
pub fn move_and_collide(
&self,
rel_vec: Vector2,
infinite_inertia: bool,
exclude_raycast_shapes: bool,
test_only: bool
) -> Option<Ref<KinematicCollision2D, Shared>>
[src]
&self,
rel_vec: Vector2,
infinite_inertia: bool,
exclude_raycast_shapes: bool,
test_only: bool
) -> Option<Ref<KinematicCollision2D, Shared>>
Moves the body along the vector [code]rel_vec[/code]. The body will stop if it collides. Returns a [KinematicCollision2D], which contains information about the collision.
If [code]test_only[/code] is [code]true[/code], the body does not move but the would-be collision information is given.
Default Arguments
infinite_inertia
-true
exclude_raycast_shapes
-true
test_only
-false
pub fn move_and_slide(
&self,
linear_velocity: Vector2,
up_direction: Vector2,
stop_on_slope: bool,
max_slides: i64,
floor_max_angle: f64,
infinite_inertia: bool
) -> Vector2
[src]
&self,
linear_velocity: Vector2,
up_direction: Vector2,
stop_on_slope: bool,
max_slides: i64,
floor_max_angle: f64,
infinite_inertia: bool
) -> Vector2
Moves the body along a vector. If the body collides with another, it will slide along the other body rather than stop immediately. If the other body is a [KinematicBody2D] or [RigidBody2D], it will also be affected by the motion of the other body. You can use this to make moving or rotating platforms, or to make nodes push other nodes.
This method should be used in [method Node._physics_process] (or in a method called by [method Node._physics_process]), as it uses the physics step's [code]delta[/code] value automatically in calculations. Otherwise, the simulation will run at an incorrect speed.
[code]linear_velocity[/code] is the velocity vector in pixels per second. Unlike in [method move_and_collide], you should [i]not[/i] multiply it by [code]delta[/code] — the physics engine handles applying the velocity.
[code]up_direction[/code] is the up direction, used to determine what is a wall and what is a floor or a ceiling. If set to the default value of [code]Vector2(0, 0)[/code], everything is considered a wall. This is useful for topdown games.
If [code]stop_on_slope[/code] is [code]true[/code], body will not slide on slopes when you include gravity in [code]linear_velocity[/code] and the body is standing still.
If the body collides, it will change direction a maximum of [code]max_slides[/code] times before it stops.
[code]floor_max_angle[/code] is the maximum angle (in radians) where a slope is still considered a floor (or a ceiling), rather than a wall. The default value equals 45 degrees.
If [code]infinite_inertia[/code] is [code]true[/code], body will be able to push [RigidBody2D] nodes, but it won't also detect any collisions with them. If [code]false[/code], it will interact with [RigidBody2D] nodes like with [StaticBody2D].
Returns the [code]linear_velocity[/code] vector, rotated and/or scaled if a slide collision occurred. To get detailed information about collisions that occurred, use [method get_slide_collision].
Default Arguments
up_direction
-Vector2( 0, 0 )
stop_on_slope
-false
max_slides
-4
floor_max_angle
-0.785398
infinite_inertia
-true
pub fn move_and_slide_with_snap(
&self,
linear_velocity: Vector2,
snap: Vector2,
up_direction: Vector2,
stop_on_slope: bool,
max_slides: i64,
floor_max_angle: f64,
infinite_inertia: bool
) -> Vector2
[src]
&self,
linear_velocity: Vector2,
snap: Vector2,
up_direction: Vector2,
stop_on_slope: bool,
max_slides: i64,
floor_max_angle: f64,
infinite_inertia: bool
) -> Vector2
Moves the body while keeping it attached to slopes. Similar to [method move_and_slide].
As long as the [code]snap[/code] vector is in contact with the ground, the body will remain attached to the surface. This means you must disable snap in order to jump, for example. You can do this by setting [code]snap[/code] to [code](0, 0)[/code] or by using [method move_and_slide] instead.
Default Arguments
up_direction
-Vector2( 0, 0 )
stop_on_slope
-false
max_slides
-4
floor_max_angle
-0.785398
infinite_inertia
-true
pub fn set_safe_margin(&self, pixels: f64)
[src]
If the body is at least this close to another body, this body will consider them to be colliding.
pub fn set_sync_to_physics(&self, enable: bool)
[src]
If [code]true[/code], the body's movement will be synchronized to the physics frame. This is useful when animating movement via [AnimationPlayer], for example on moving platforms. Do [b]not[/b] use together with [method move_and_slide] or [method move_and_collide] functions.
pub fn test_move(
&self,
from: Transform2D,
rel_vec: Vector2,
infinite_inertia: bool
) -> bool
[src]
&self,
from: Transform2D,
rel_vec: Vector2,
infinite_inertia: bool
) -> bool
Checks for collisions without moving the body. Virtually sets the node's position, scale and rotation to that of the given [Transform2D], then tries to move the body along the vector [code]rel_vec[/code]. Returns [code]true[/code] if a collision would occur.
Default Arguments
infinite_inertia
-true
Methods from Deref<Target = PhysicsBody2D>
pub fn add_collision_exception_with(&self, body: impl AsArg<Node>)
[src]
Adds a body to the list of bodies that this body can't collide with.
pub fn get_collision_exceptions(&self) -> VariantArray
[src]
Returns an array of nodes that were added as collision exceptions for this body.
pub fn collision_layer(&self) -> i64
[src]
The physics layers this area is in.
Collidable objects can exist in any of 32 different layers. These layers work like a tagging system, and are not visual. A collidable can use these layers to select with which objects it can collide, using the [member collision_mask] property.
A contact is detected if object A is in any of the layers that object B scans, or object B is in any layer scanned by object A. See [url=https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information.
pub fn get_collision_layer_bit(&self, bit: i64) -> bool
[src]
Returns an individual bit on the [member collision_layer].
pub fn collision_mask(&self) -> i64
[src]
The physics layers this area scans for collisions. See [url=https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information.
pub fn get_collision_mask_bit(&self, bit: i64) -> bool
[src]
Returns an individual bit on the [member collision_mask].
pub fn remove_collision_exception_with(&self, body: impl AsArg<Node>)
[src]
Removes a body from the list of bodies that this body can't collide with.
pub fn set_collision_layer(&self, layer: i64)
[src]
The physics layers this area is in.
Collidable objects can exist in any of 32 different layers. These layers work like a tagging system, and are not visual. A collidable can use these layers to select with which objects it can collide, using the [member collision_mask] property.
A contact is detected if object A is in any of the layers that object B scans, or object B is in any layer scanned by object A. See [url=https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information.
pub fn set_collision_layer_bit(&self, bit: i64, value: bool)
[src]
Sets individual bits on the [member collision_layer] bitmask. Use this if you only need to change one layer's value.
pub fn set_collision_mask(&self, mask: i64)
[src]
The physics layers this area scans for collisions. See [url=https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information.
pub fn set_collision_mask_bit(&self, bit: i64, value: bool)
[src]
Sets individual bits on the [member collision_mask] bitmask. Use this if you only need to change one layer's value.
Trait Implementations
impl Debug for KinematicBody2D
[src]
impl Deref for KinematicBody2D
[src]
type Target = PhysicsBody2D
The resulting type after dereferencing.
fn deref(&self) -> &PhysicsBody2D
[src]
impl DerefMut for KinematicBody2D
[src]
fn deref_mut(&mut self) -> &mut PhysicsBody2D
[src]
impl GodotObject for KinematicBody2D
[src]
type RefKind = ManuallyManaged
The memory management kind of this type. This modifies the behavior of the
Ref
smart pointer. See its type-level documentation for more
information. Read more
fn class_name() -> &'static str
[src]
fn null() -> Null<Self>
[src]
fn new() -> Ref<Self, Unique> where
Self: Instanciable,
[src]
Self: Instanciable,
fn cast<T>(&self) -> Option<&T> where
T: GodotObject + SubClass<Self>,
[src]
T: GodotObject + SubClass<Self>,
fn upcast<T>(&self) -> &T where
Self: SubClass<T>,
T: GodotObject,
[src]
Self: SubClass<T>,
T: GodotObject,
unsafe fn assume_shared(&self) -> Ref<Self, Shared>
[src]
unsafe fn assume_thread_local(&self) -> Ref<Self, ThreadLocal> where
Self: GodotObject<RefKind = RefCounted>,
[src]
Self: GodotObject<RefKind = RefCounted>,
unsafe fn assume_unique(&self) -> Ref<Self, Unique>
[src]
impl Instanciable for KinematicBody2D
[src]
impl QueueFree for KinematicBody2D
[src]
unsafe fn godot_queue_free(obj: *mut godot_object)
[src]
impl Sealed for KinematicBody2D
[src]
impl SubClass<CanvasItem> for KinematicBody2D
[src]
impl SubClass<CollisionObject2D> for KinematicBody2D
[src]
impl SubClass<Node> for KinematicBody2D
[src]
impl SubClass<Node2D> for KinematicBody2D
[src]
impl SubClass<Object> for KinematicBody2D
[src]
impl SubClass<PhysicsBody2D> for KinematicBody2D
[src]
Auto Trait Implementations
impl RefUnwindSafe for KinematicBody2D
impl !Send for KinematicBody2D
impl !Sync for KinematicBody2D
impl Unpin for KinematicBody2D
impl UnwindSafe for KinematicBody2D
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> SubClass<T> for T where
T: GodotObject,
[src]
T: GodotObject,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,