123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719 |
- :github_url: hide
- .. DO NOT EDIT THIS FILE!!!
- .. Generated automatically from Godot engine sources.
- .. Generator: https://github.com/godotengine/godot/tree/4.2/doc/tools/make_rst.py.
- .. XML source: https://github.com/godotengine/godot/tree/4.2/doc/classes/CharacterBody2D.xml.
- .. _class_CharacterBody2D:
- CharacterBody2D
- ===============
- **Inherits:** :ref:`PhysicsBody2D<class_PhysicsBody2D>` **<** :ref:`CollisionObject2D<class_CollisionObject2D>` **<** :ref:`Node2D<class_Node2D>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
- A 2D physics body specialized for characters moved by script.
- .. rst-class:: classref-introduction-group
- Description
- -----------
- **CharacterBody2D** is a specialized class for physics bodies that are meant to be user-controlled. They are not affected by physics at all, but they affect other physics bodies in their path. They are mainly used to provide high-level API to move objects with wall and slope detection (:ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>` method) in addition to the general collision detection provided by :ref:`PhysicsBody2D.move_and_collide<class_PhysicsBody2D_method_move_and_collide>`. This makes it useful for highly configurable physics bodies that must move in specific ways and collide with the world, as is often the case with user-controlled characters.
- For game objects that don't require complex movement or collision detection, such as moving platforms, :ref:`AnimatableBody2D<class_AnimatableBody2D>` is simpler to configure.
- .. rst-class:: classref-introduction-group
- Tutorials
- ---------
- - :doc:`Kinematic character (2D) <../tutorials/physics/kinematic_character_2d>`
- - :doc:`Using CharacterBody2D <../tutorials/physics/using_character_body_2d>`
- - `2D Kinematic Character Demo <https://godotengine.org/asset-library/asset/113>`__
- - `2D Platformer Demo <https://godotengine.org/asset-library/asset/120>`__
- .. rst-class:: classref-reftable-group
- Properties
- ----------
- .. table::
- :widths: auto
- +--------------------------------------------------------------+------------------------------------------------------------------------------------+--------------------+
- | :ref:`bool<class_bool>` | :ref:`floor_block_on_wall<class_CharacterBody2D_property_floor_block_on_wall>` | ``true`` |
- +--------------------------------------------------------------+------------------------------------------------------------------------------------+--------------------+
- | :ref:`bool<class_bool>` | :ref:`floor_constant_speed<class_CharacterBody2D_property_floor_constant_speed>` | ``false`` |
- +--------------------------------------------------------------+------------------------------------------------------------------------------------+--------------------+
- | :ref:`float<class_float>` | :ref:`floor_max_angle<class_CharacterBody2D_property_floor_max_angle>` | ``0.785398`` |
- +--------------------------------------------------------------+------------------------------------------------------------------------------------+--------------------+
- | :ref:`float<class_float>` | :ref:`floor_snap_length<class_CharacterBody2D_property_floor_snap_length>` | ``1.0`` |
- +--------------------------------------------------------------+------------------------------------------------------------------------------------+--------------------+
- | :ref:`bool<class_bool>` | :ref:`floor_stop_on_slope<class_CharacterBody2D_property_floor_stop_on_slope>` | ``true`` |
- +--------------------------------------------------------------+------------------------------------------------------------------------------------+--------------------+
- | :ref:`int<class_int>` | :ref:`max_slides<class_CharacterBody2D_property_max_slides>` | ``4`` |
- +--------------------------------------------------------------+------------------------------------------------------------------------------------+--------------------+
- | :ref:`MotionMode<enum_CharacterBody2D_MotionMode>` | :ref:`motion_mode<class_CharacterBody2D_property_motion_mode>` | ``0`` |
- +--------------------------------------------------------------+------------------------------------------------------------------------------------+--------------------+
- | :ref:`int<class_int>` | :ref:`platform_floor_layers<class_CharacterBody2D_property_platform_floor_layers>` | ``4294967295`` |
- +--------------------------------------------------------------+------------------------------------------------------------------------------------+--------------------+
- | :ref:`PlatformOnLeave<enum_CharacterBody2D_PlatformOnLeave>` | :ref:`platform_on_leave<class_CharacterBody2D_property_platform_on_leave>` | ``0`` |
- +--------------------------------------------------------------+------------------------------------------------------------------------------------+--------------------+
- | :ref:`int<class_int>` | :ref:`platform_wall_layers<class_CharacterBody2D_property_platform_wall_layers>` | ``0`` |
- +--------------------------------------------------------------+------------------------------------------------------------------------------------+--------------------+
- | :ref:`float<class_float>` | :ref:`safe_margin<class_CharacterBody2D_property_safe_margin>` | ``0.08`` |
- +--------------------------------------------------------------+------------------------------------------------------------------------------------+--------------------+
- | :ref:`bool<class_bool>` | :ref:`slide_on_ceiling<class_CharacterBody2D_property_slide_on_ceiling>` | ``true`` |
- +--------------------------------------------------------------+------------------------------------------------------------------------------------+--------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`up_direction<class_CharacterBody2D_property_up_direction>` | ``Vector2(0, -1)`` |
- +--------------------------------------------------------------+------------------------------------------------------------------------------------+--------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`velocity<class_CharacterBody2D_property_velocity>` | ``Vector2(0, 0)`` |
- +--------------------------------------------------------------+------------------------------------------------------------------------------------+--------------------+
- | :ref:`float<class_float>` | :ref:`wall_min_slide_angle<class_CharacterBody2D_property_wall_min_slide_angle>` | ``0.261799`` |
- +--------------------------------------------------------------+------------------------------------------------------------------------------------+--------------------+
- .. rst-class:: classref-reftable-group
- Methods
- -------
- .. table::
- :widths: auto
- +---------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`apply_floor_snap<class_CharacterBody2D_method_apply_floor_snap>` **(** **)** |
- +---------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`get_floor_angle<class_CharacterBody2D_method_get_floor_angle>` **(** :ref:`Vector2<class_Vector2>` up_direction=Vector2(0, -1) **)** |const| |
- +---------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`get_floor_normal<class_CharacterBody2D_method_get_floor_normal>` **(** **)** |const| |
- +---------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`get_last_motion<class_CharacterBody2D_method_get_last_motion>` **(** **)** |const| |
- +---------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`KinematicCollision2D<class_KinematicCollision2D>` | :ref:`get_last_slide_collision<class_CharacterBody2D_method_get_last_slide_collision>` **(** **)** |
- +---------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`get_platform_velocity<class_CharacterBody2D_method_get_platform_velocity>` **(** **)** |const| |
- +---------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`get_position_delta<class_CharacterBody2D_method_get_position_delta>` **(** **)** |const| |
- +---------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`get_real_velocity<class_CharacterBody2D_method_get_real_velocity>` **(** **)** |const| |
- +---------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`KinematicCollision2D<class_KinematicCollision2D>` | :ref:`get_slide_collision<class_CharacterBody2D_method_get_slide_collision>` **(** :ref:`int<class_int>` slide_idx **)** |
- +---------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`int<class_int>` | :ref:`get_slide_collision_count<class_CharacterBody2D_method_get_slide_collision_count>` **(** **)** |const| |
- +---------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`get_wall_normal<class_CharacterBody2D_method_get_wall_normal>` **(** **)** |const| |
- +---------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`is_on_ceiling<class_CharacterBody2D_method_is_on_ceiling>` **(** **)** |const| |
- +---------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`is_on_ceiling_only<class_CharacterBody2D_method_is_on_ceiling_only>` **(** **)** |const| |
- +---------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`is_on_floor<class_CharacterBody2D_method_is_on_floor>` **(** **)** |const| |
- +---------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`is_on_floor_only<class_CharacterBody2D_method_is_on_floor_only>` **(** **)** |const| |
- +---------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`is_on_wall<class_CharacterBody2D_method_is_on_wall>` **(** **)** |const| |
- +---------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`is_on_wall_only<class_CharacterBody2D_method_is_on_wall_only>` **(** **)** |const| |
- +---------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>` **(** **)** |
- +---------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Enumerations
- ------------
- .. _enum_CharacterBody2D_MotionMode:
- .. rst-class:: classref-enumeration
- enum **MotionMode**:
- .. _class_CharacterBody2D_constant_MOTION_MODE_GROUNDED:
- .. rst-class:: classref-enumeration-constant
- :ref:`MotionMode<enum_CharacterBody2D_MotionMode>` **MOTION_MODE_GROUNDED** = ``0``
- 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.
- .. _class_CharacterBody2D_constant_MOTION_MODE_FLOATING:
- .. rst-class:: classref-enumeration-constant
- :ref:`MotionMode<enum_CharacterBody2D_MotionMode>` **MOTION_MODE_FLOATING** = ``1``
- 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.
- .. rst-class:: classref-item-separator
- ----
- .. _enum_CharacterBody2D_PlatformOnLeave:
- .. rst-class:: classref-enumeration
- enum **PlatformOnLeave**:
- .. _class_CharacterBody2D_constant_PLATFORM_ON_LEAVE_ADD_VELOCITY:
- .. rst-class:: classref-enumeration-constant
- :ref:`PlatformOnLeave<enum_CharacterBody2D_PlatformOnLeave>` **PLATFORM_ON_LEAVE_ADD_VELOCITY** = ``0``
- Add the last platform velocity to the :ref:`velocity<class_CharacterBody2D_property_velocity>` when you leave a moving platform.
- .. _class_CharacterBody2D_constant_PLATFORM_ON_LEAVE_ADD_UPWARD_VELOCITY:
- .. rst-class:: classref-enumeration-constant
- :ref:`PlatformOnLeave<enum_CharacterBody2D_PlatformOnLeave>` **PLATFORM_ON_LEAVE_ADD_UPWARD_VELOCITY** = ``1``
- Add the last platform velocity to the :ref:`velocity<class_CharacterBody2D_property_velocity>` when you leave a moving platform, but any downward motion is ignored. It's useful to keep full jump height even when the platform is moving down.
- .. _class_CharacterBody2D_constant_PLATFORM_ON_LEAVE_DO_NOTHING:
- .. rst-class:: classref-enumeration-constant
- :ref:`PlatformOnLeave<enum_CharacterBody2D_PlatformOnLeave>` **PLATFORM_ON_LEAVE_DO_NOTHING** = ``2``
- Do nothing when leaving a platform.
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Property Descriptions
- ---------------------
- .. _class_CharacterBody2D_property_floor_block_on_wall:
- .. rst-class:: classref-property
- :ref:`bool<class_bool>` **floor_block_on_wall** = ``true``
- .. rst-class:: classref-property-setget
- - void **set_floor_block_on_wall_enabled** **(** :ref:`bool<class_bool>` value **)**
- - :ref:`bool<class_bool>` **is_floor_block_on_wall_enabled** **(** **)**
- 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.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_property_floor_constant_speed:
- .. rst-class:: classref-property
- :ref:`bool<class_bool>` **floor_constant_speed** = ``false``
- .. rst-class:: classref-property-setget
- - void **set_floor_constant_speed_enabled** **(** :ref:`bool<class_bool>` value **)**
- - :ref:`bool<class_bool>` **is_floor_constant_speed_enabled** **(** **)**
- If ``false`` (by default), the body will move faster on downward slopes and slower on upward slopes.
- If ``true``, the body will always move at the same speed on the ground no matter the slope. Note that you need to use :ref:`floor_snap_length<class_CharacterBody2D_property_floor_snap_length>` to stick along a downward slope at constant speed.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_property_floor_max_angle:
- .. rst-class:: classref-property
- :ref:`float<class_float>` **floor_max_angle** = ``0.785398``
- .. rst-class:: classref-property-setget
- - void **set_floor_max_angle** **(** :ref:`float<class_float>` value **)**
- - :ref:`float<class_float>` **get_floor_max_angle** **(** **)**
- Maximum angle (in radians) where a slope is still considered a floor (or a ceiling), rather than a wall, when calling :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>`. The default value equals 45 degrees.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_property_floor_snap_length:
- .. rst-class:: classref-property
- :ref:`float<class_float>` **floor_snap_length** = ``1.0``
- .. rst-class:: classref-property-setget
- - void **set_floor_snap_length** **(** :ref:`float<class_float>` value **)**
- - :ref:`float<class_float>` **get_floor_snap_length** **(** **)**
- Sets a snapping distance. When set to a value different from ``0.0``, the body is kept attached to slopes when calling :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>`. The snapping vector is determined by the given distance along the opposite direction of the :ref:`up_direction<class_CharacterBody2D_property_up_direction>`.
- As long as the snapping vector is in contact with the ground and the body moves against :ref:`up_direction<class_CharacterBody2D_property_up_direction>`, the body will remain attached to the surface. Snapping is not applied if the body moves along :ref:`up_direction<class_CharacterBody2D_property_up_direction>`, meaning it contains vertical rising velocity, so it will be able to detach from the ground when jumping or when the body is pushed up by something. If you want to apply a snap without taking into account the velocity, use :ref:`apply_floor_snap<class_CharacterBody2D_method_apply_floor_snap>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_property_floor_stop_on_slope:
- .. rst-class:: classref-property
- :ref:`bool<class_bool>` **floor_stop_on_slope** = ``true``
- .. rst-class:: classref-property-setget
- - void **set_floor_stop_on_slope_enabled** **(** :ref:`bool<class_bool>` value **)**
- - :ref:`bool<class_bool>` **is_floor_stop_on_slope_enabled** **(** **)**
- If ``true``, the body will not slide on slopes when calling :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>` when the body is standing still.
- If ``false``, the body will slide on floor's slopes when :ref:`velocity<class_CharacterBody2D_property_velocity>` applies a downward force.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_property_max_slides:
- .. rst-class:: classref-property
- :ref:`int<class_int>` **max_slides** = ``4``
- .. rst-class:: classref-property-setget
- - void **set_max_slides** **(** :ref:`int<class_int>` value **)**
- - :ref:`int<class_int>` **get_max_slides** **(** **)**
- Maximum number of times the body can change direction before it stops when calling :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_property_motion_mode:
- .. rst-class:: classref-property
- :ref:`MotionMode<enum_CharacterBody2D_MotionMode>` **motion_mode** = ``0``
- .. rst-class:: classref-property-setget
- - void **set_motion_mode** **(** :ref:`MotionMode<enum_CharacterBody2D_MotionMode>` value **)**
- - :ref:`MotionMode<enum_CharacterBody2D_MotionMode>` **get_motion_mode** **(** **)**
- Sets the motion mode which defines the behavior of :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>`. See :ref:`MotionMode<enum_CharacterBody2D_MotionMode>` constants for available modes.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_property_platform_floor_layers:
- .. rst-class:: classref-property
- :ref:`int<class_int>` **platform_floor_layers** = ``4294967295``
- .. rst-class:: classref-property-setget
- - void **set_platform_floor_layers** **(** :ref:`int<class_int>` value **)**
- - :ref:`int<class_int>` **get_platform_floor_layers** **(** **)**
- 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.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_property_platform_on_leave:
- .. rst-class:: classref-property
- :ref:`PlatformOnLeave<enum_CharacterBody2D_PlatformOnLeave>` **platform_on_leave** = ``0``
- .. rst-class:: classref-property-setget
- - void **set_platform_on_leave** **(** :ref:`PlatformOnLeave<enum_CharacterBody2D_PlatformOnLeave>` value **)**
- - :ref:`PlatformOnLeave<enum_CharacterBody2D_PlatformOnLeave>` **get_platform_on_leave** **(** **)**
- 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 :ref:`PlatformOnLeave<enum_CharacterBody2D_PlatformOnLeave>` constants for available behavior.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_property_platform_wall_layers:
- .. rst-class:: classref-property
- :ref:`int<class_int>` **platform_wall_layers** = ``0``
- .. rst-class:: classref-property-setget
- - void **set_platform_wall_layers** **(** :ref:`int<class_int>` value **)**
- - :ref:`int<class_int>` **get_platform_wall_layers** **(** **)**
- 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.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_property_safe_margin:
- .. rst-class:: classref-property
- :ref:`float<class_float>` **safe_margin** = ``0.08``
- .. rst-class:: classref-property-setget
- - void **set_safe_margin** **(** :ref:`float<class_float>` value **)**
- - :ref:`float<class_float>` **get_safe_margin** **(** **)**
- Extra margin used for collision recovery when calling :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>`.
- If the body is at least this close to another body, it will consider them to be colliding and will be pushed away before performing the actual motion.
- A higher value means it's more flexible for detecting collision, which helps with consistently detecting walls and floors.
- A lower value forces the collision algorithm to use more exact detection, so it can be used in cases that specifically require precision, e.g at very low scale to avoid visible jittering, or for stability with a stack of character bodies.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_property_slide_on_ceiling:
- .. rst-class:: classref-property
- :ref:`bool<class_bool>` **slide_on_ceiling** = ``true``
- .. rst-class:: classref-property-setget
- - void **set_slide_on_ceiling_enabled** **(** :ref:`bool<class_bool>` value **)**
- - :ref:`bool<class_bool>` **is_slide_on_ceiling_enabled** **(** **)**
- If ``true``, during a jump against the ceiling, the body will slide, if ``false`` it will be stopped and will fall vertically.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_property_up_direction:
- .. rst-class:: classref-property
- :ref:`Vector2<class_Vector2>` **up_direction** = ``Vector2(0, -1)``
- .. rst-class:: classref-property-setget
- - void **set_up_direction** **(** :ref:`Vector2<class_Vector2>` value **)**
- - :ref:`Vector2<class_Vector2>` **get_up_direction** **(** **)**
- Vector pointing upwards, used to determine what is a wall and what is a floor (or a ceiling) when calling :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>`. Defaults to :ref:`Vector2.UP<class_Vector2_constant_UP>`. As the vector will be normalized it can't be equal to :ref:`Vector2.ZERO<class_Vector2_constant_ZERO>`, if you want all collisions to be reported as walls, consider using :ref:`MOTION_MODE_FLOATING<class_CharacterBody2D_constant_MOTION_MODE_FLOATING>` as :ref:`motion_mode<class_CharacterBody2D_property_motion_mode>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_property_velocity:
- .. rst-class:: classref-property
- :ref:`Vector2<class_Vector2>` **velocity** = ``Vector2(0, 0)``
- .. rst-class:: classref-property-setget
- - void **set_velocity** **(** :ref:`Vector2<class_Vector2>` value **)**
- - :ref:`Vector2<class_Vector2>` **get_velocity** **(** **)**
- Current velocity vector in pixels per second, used and modified during calls to :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_property_wall_min_slide_angle:
- .. rst-class:: classref-property
- :ref:`float<class_float>` **wall_min_slide_angle** = ``0.261799``
- .. rst-class:: classref-property-setget
- - void **set_wall_min_slide_angle** **(** :ref:`float<class_float>` value **)**
- - :ref:`float<class_float>` **get_wall_min_slide_angle** **(** **)**
- 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 :ref:`motion_mode<class_CharacterBody2D_property_motion_mode>` is :ref:`MOTION_MODE_FLOATING<class_CharacterBody2D_constant_MOTION_MODE_FLOATING>`.
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Method Descriptions
- -------------------
- .. _class_CharacterBody2D_method_apply_floor_snap:
- .. rst-class:: classref-method
- void **apply_floor_snap** **(** **)**
- Allows to manually apply a snap to the floor regardless of the body's velocity. This function does nothing when :ref:`is_on_floor<class_CharacterBody2D_method_is_on_floor>` returns ``true``.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_method_get_floor_angle:
- .. rst-class:: classref-method
- :ref:`float<class_float>` **get_floor_angle** **(** :ref:`Vector2<class_Vector2>` up_direction=Vector2(0, -1) **)** |const|
- Returns the floor's collision angle at the last collision point according to ``up_direction``, which is :ref:`Vector2.UP<class_Vector2_constant_UP>` by default. This value is always positive and only valid after calling :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>` and when :ref:`is_on_floor<class_CharacterBody2D_method_is_on_floor>` returns ``true``.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_method_get_floor_normal:
- .. rst-class:: classref-method
- :ref:`Vector2<class_Vector2>` **get_floor_normal** **(** **)** |const|
- Returns the surface normal of the floor at the last collision point. Only valid after calling :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>` and when :ref:`is_on_floor<class_CharacterBody2D_method_is_on_floor>` returns ``true``.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_method_get_last_motion:
- .. rst-class:: classref-method
- :ref:`Vector2<class_Vector2>` **get_last_motion** **(** **)** |const|
- Returns the last motion applied to the **CharacterBody2D** during the last call to :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>`. 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.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_method_get_last_slide_collision:
- .. rst-class:: classref-method
- :ref:`KinematicCollision2D<class_KinematicCollision2D>` **get_last_slide_collision** **(** **)**
- Returns a :ref:`KinematicCollision2D<class_KinematicCollision2D>`, which contains information about the latest collision that occurred during the last call to :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_method_get_platform_velocity:
- .. rst-class:: classref-method
- :ref:`Vector2<class_Vector2>` **get_platform_velocity** **(** **)** |const|
- Returns the linear velocity of the platform at the last collision point. Only valid after calling :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_method_get_position_delta:
- .. rst-class:: classref-method
- :ref:`Vector2<class_Vector2>` **get_position_delta** **(** **)** |const|
- Returns the travel (position delta) that occurred during the last call to :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_method_get_real_velocity:
- .. rst-class:: classref-method
- :ref:`Vector2<class_Vector2>` **get_real_velocity** **(** **)** |const|
- Returns the current real velocity since the last call to :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>`. 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 to :ref:`velocity<class_CharacterBody2D_property_velocity>` which returns the requested velocity.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_method_get_slide_collision:
- .. rst-class:: classref-method
- :ref:`KinematicCollision2D<class_KinematicCollision2D>` **get_slide_collision** **(** :ref:`int<class_int>` slide_idx **)**
- Returns a :ref:`KinematicCollision2D<class_KinematicCollision2D>`, which contains information about a collision that occurred during the last call to :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>`. Since the body can collide several times in a single call to :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>`, you must specify the index of the collision in the range 0 to (:ref:`get_slide_collision_count<class_CharacterBody2D_method_get_slide_collision_count>` - 1).
- \ **Example usage:**\
- .. tabs::
- .. code-tab:: gdscript
- for i in get_slide_collision_count():
- var collision = get_slide_collision(i)
- print("Collided with: ", collision.get_collider().name)
- .. code-tab:: csharp
- for (int i = 0; i < GetSlideCollisionCount(); i++)
- {
- KinematicCollision2D collision = GetSlideCollision(i);
- GD.Print("Collided with: ", (collision.GetCollider() as Node).Name);
- }
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_method_get_slide_collision_count:
- .. rst-class:: classref-method
- :ref:`int<class_int>` **get_slide_collision_count** **(** **)** |const|
- Returns the number of times the body collided and changed direction during the last call to :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_method_get_wall_normal:
- .. rst-class:: classref-method
- :ref:`Vector2<class_Vector2>` **get_wall_normal** **(** **)** |const|
- Returns the surface normal of the wall at the last collision point. Only valid after calling :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>` and when :ref:`is_on_wall<class_CharacterBody2D_method_is_on_wall>` returns ``true``.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_method_is_on_ceiling:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **is_on_ceiling** **(** **)** |const|
- Returns ``true`` if the body collided with the ceiling on the last call of :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>`. Otherwise, returns ``false``. The :ref:`up_direction<class_CharacterBody2D_property_up_direction>` and :ref:`floor_max_angle<class_CharacterBody2D_property_floor_max_angle>` are used to determine whether a surface is "ceiling" or not.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_method_is_on_ceiling_only:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **is_on_ceiling_only** **(** **)** |const|
- Returns ``true`` if the body collided only with the ceiling on the last call of :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>`. Otherwise, returns ``false``. The :ref:`up_direction<class_CharacterBody2D_property_up_direction>` and :ref:`floor_max_angle<class_CharacterBody2D_property_floor_max_angle>` are used to determine whether a surface is "ceiling" or not.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_method_is_on_floor:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **is_on_floor** **(** **)** |const|
- Returns ``true`` if the body collided with the floor on the last call of :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>`. Otherwise, returns ``false``. The :ref:`up_direction<class_CharacterBody2D_property_up_direction>` and :ref:`floor_max_angle<class_CharacterBody2D_property_floor_max_angle>` are used to determine whether a surface is "floor" or not.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_method_is_on_floor_only:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **is_on_floor_only** **(** **)** |const|
- Returns ``true`` if the body collided only with the floor on the last call of :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>`. Otherwise, returns ``false``. The :ref:`up_direction<class_CharacterBody2D_property_up_direction>` and :ref:`floor_max_angle<class_CharacterBody2D_property_floor_max_angle>` are used to determine whether a surface is "floor" or not.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_method_is_on_wall:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **is_on_wall** **(** **)** |const|
- Returns ``true`` if the body collided with a wall on the last call of :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>`. Otherwise, returns ``false``. The :ref:`up_direction<class_CharacterBody2D_property_up_direction>` and :ref:`floor_max_angle<class_CharacterBody2D_property_floor_max_angle>` are used to determine whether a surface is "wall" or not.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_method_is_on_wall_only:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **is_on_wall_only** **(** **)** |const|
- Returns ``true`` if the body collided only with a wall on the last call of :ref:`move_and_slide<class_CharacterBody2D_method_move_and_slide>`. Otherwise, returns ``false``. The :ref:`up_direction<class_CharacterBody2D_property_up_direction>` and :ref:`floor_max_angle<class_CharacterBody2D_property_floor_max_angle>` are used to determine whether a surface is "wall" or not.
- .. rst-class:: classref-item-separator
- ----
- .. _class_CharacterBody2D_method_move_and_slide:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **move_and_slide** **(** **)**
- Moves the body based on :ref:`velocity<class_CharacterBody2D_property_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 a **CharacterBody2D** or :ref:`RigidBody2D<class_RigidBody2D>`, 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.
- Modifies :ref:`velocity<class_CharacterBody2D_property_velocity>` if a slide collision occurred. To get the latest collision call :ref:`get_last_slide_collision<class_CharacterBody2D_method_get_last_slide_collision>`, for detailed information about collisions that occurred, use :ref:`get_slide_collision<class_CharacterBody2D_method_get_slide_collision>`.
- When the body touches a moving platform, the platform's velocity is automatically added to the body motion. If a collision occurs due to the platform's motion, it will always be first in the slide collisions.
- The general behavior and available properties change according to the :ref:`motion_mode<class_CharacterBody2D_property_motion_mode>`.
- Returns ``true`` if the body collided, otherwise, returns ``false``.
- .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
- .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
- .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
- .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
- .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
- .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
- .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
|