Enumerationmigueldeicaza.swiftgodot 0.46.0SwiftGodot
MotionMode
CharacterBody2D.swift:22enum MotionMode
Cases
case grounded
Apply when notions of walls, ceiling and floor are relevant. In this mode the body motion will react to slopes (acceleration/slowdown). This mode is suitable for sided games like platformers.
case floating
Apply when there is no notion of floor or ceiling. All collisions will be reported as
on_wall
. In this mode, when you slide, the speed will always be constant. This mode is suitable for top-down games.
Other members in extension
View members
Hide members
This section is hidden by default because it contains too many (35) members.
Types
Type members
Instance members
var floorBlockOnWall: Bool
If
true
, the body will be able to move on the floor only. This option avoids to be able to walk on walls, it will however allow to slide down along them.var floorConstantSpeed: Bool
If
false
(by default), the body will move faster on downward slopes and slower on upward slopes.var floorMaxAngle: Double
Maximum angle (in radians) where a slope is still considered a floor (or a ceiling), rather than a wall, when calling
moveAndSlide
. The default value equals 45 degrees.var floorSnapLength: Double
Sets a snapping distance. When set to a value different from
0.0
, the body is kept attached to slopes when callingmoveAndSlide
. The snapping vector is determined by the given distance along the opposite direction of theupDirection
.var floorStopOnSlope: Bool
If
true
, the body will not slide on slopes when callingmoveAndSlide
when the body is standing still.var maxSlides: Int32
Maximum number of times the body can change direction before it stops when calling
moveAndSlide
.var motionMode: CharacterBody2D.MotionMode
Sets the motion mode which defines the behavior of
moveAndSlide
. SeeMotionMode
constants for available modes.var platformFloorLayers: UInt32
Collision layers that will be included for detecting floor bodies that will act as moving platforms to be followed by the
CharacterBody2D
. By default, all floor bodies are detected and propagate their velocity.var platformOnLeave: CharacterBody2D.PlatformOnLeave
Sets the behavior to apply when you leave a moving platform. By default, to be physically accurate, when you leave the last platform velocity is applied. See
PlatformOnLeave
constants for available behavior.var platformWallLayers: UInt32
Collision layers that will be included for detecting wall bodies that will act as moving platforms to be followed by the
CharacterBody2D
. By default, all wall bodies are ignored.var safeMargin: Double
Extra margin used for collision recovery when calling
moveAndSlide
.var slideOnCeiling: Bool
If
true
, during a jump against the ceiling, the body will slide, iffalse
it will be stopped and will fall vertically.var upDirection: Vector2
Vector pointing upwards, used to determine what is a wall and what is a floor (or a ceiling) when calling
moveAndSlide
. Defaults toVector2.UP
. As the vector will be normalized it can’t be equal toVector2.ZERO
, if you want all collisions to be reported as walls, consider using .floating asmotionMode
.var velocity: Vector2
Current velocity vector in pixels per second, used and modified during calls to
moveAndSlide
.var wallMinSlideAngle: Double
Minimum angle (in radians) where the body is allowed to slide when it encounters a slope. The default value equals 15 degrees. This property only affects movement when
motionMode
is .floating.func applyFloorSnap(
) Allows to manually apply a snap to the floor regardless of the body’s velocity. This function does nothing when
isOnFloor
returnstrue
.func getFloorAngle(upDirection: Vector2
) -> Double Returns the floor’s collision angle at the last collision point according to
upDirection
, which isVector2.UP
by default. This value is always positive and only valid after callingmoveAndSlide
and whenisOnFloor
returnstrue
.func getFloorNormal(
) -> Vector2 Returns the collision normal of the floor at the last collision point. Only valid after calling
moveAndSlide
and whenisOnFloor
returnstrue
.func getLastMotion(
) -> Vector2 Returns the last motion applied to the
CharacterBody2D
during the last call tomoveAndSlide
. The movement can be split into multiple motions when sliding occurs, and this method return the last one, which is useful to retrieve the current direction of the movement.func getLastSlideCollision(
) -> KinematicCollision2D? Returns a
KinematicCollision2D
, which contains information about the latest collision that occurred during the last call tomoveAndSlide
.func getPlatformVelocity(
) -> Vector2 Returns the linear velocity of the platform at the last collision point. Only valid after calling
moveAndSlide
.func getPositionDelta(
) -> Vector2 Returns the travel (position delta) that occurred during the last call to
moveAndSlide
.func getRealVelocity(
) -> Vector2 Returns the current real velocity since the last call to
moveAndSlide
. For example, when you climb a slope, you will move diagonally even though the velocity is horizontal. This method returns the diagonal movement, as opposed tovelocity
which returns the requested velocity.func getSlideCollision(slideIdx: Int32
) -> KinematicCollision2D? Returns a
KinematicCollision2D
, which contains information about a collision that occurred during the last call tomoveAndSlide
. Since the body can collide several times in a single call tomoveAndSlide
, you must specify the index of the collision in the range 0 to (getSlideCollisionCount
- 1).func getSlideCollisionCount(
) -> Int32 Returns the number of times the body collided and changed direction during the last call to
moveAndSlide
.func getWallNormal(
) -> Vector2 Returns the collision normal of the wall at the last collision point. Only valid after calling
moveAndSlide
and whenisOnWall
returnstrue
.func isOnCeiling(
) -> Bool Returns
true
if the body collided with the ceiling on the last call ofmoveAndSlide
. Otherwise, returnsfalse
. TheupDirection
andfloorMaxAngle
are used to determine whether a surface is “ceiling” or not.func isOnCeilingOnly(
) -> Bool Returns
true
if the body collided only with the ceiling on the last call ofmoveAndSlide
. Otherwise, returnsfalse
. TheupDirection
andfloorMaxAngle
are used to determine whether a surface is “ceiling” or not.func isOnFloor(
) -> Bool Returns
true
if the body collided with the floor on the last call ofmoveAndSlide
. Otherwise, returnsfalse
. TheupDirection
andfloorMaxAngle
are used to determine whether a surface is “floor” or not.func isOnFloorOnly(
) -> Bool Returns
true
if the body collided only with the floor on the last call ofmoveAndSlide
. Otherwise, returnsfalse
. TheupDirection
andfloorMaxAngle
are used to determine whether a surface is “floor” or not.func isOnWall(
) -> Bool Returns
true
if the body collided with a wall on the last call ofmoveAndSlide
. Otherwise, returnsfalse
. TheupDirection
andfloorMaxAngle
are used to determine whether a surface is “wall” or not.func isOnWallOnly(
) -> Bool Returns
true
if the body collided only with a wall on the last call ofmoveAndSlide
. Otherwise, returnsfalse
. TheupDirection
andfloorMaxAngle
are used to determine whether a surface is “wall” or not.func moveAndSlide(
) -> Bool Moves the body based on
velocity
. If the body collides with another, it will slide along the other body (by default only on floor) rather than stop immediately. If the other body is aCharacterBody2D
orRigidBody2D
, it will also be affected by the motion of the other body. You can use this to make moving and rotating platforms, or to make nodes push other nodes.
Citizens in SwiftGodot
Conformances
protocol CaseIterable
A type that provides a collection of all of its values.
protocol CustomDebugStringConvertible
A type with a customized textual representation suitable for debugging purposes.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol RawRepresentable<RawValue>
A type that can be converted to and from an associated raw value.
Type members
Instance members
var debugDescription: String
A textual representation of this instance, suitable for debugging
Type features
static func != (lhs: Self, rhs: Self
) -> Bool Returns a Boolean value indicating whether two values are not equal.