mirror of
https://github.com/godotengine/godot-docs-l10n.git
synced 2025-12-31 09:49:22 +03:00
728 lines
42 KiB
ReStructuredText
728 lines
42 KiB
ReStructuredText
:github_url: hide
|
|
|
|
.. _class_CharacterBody2D:
|
|
|
|
CharacterBody2D
|
|
===============
|
|
|
|
**Hereda:** :ref:`PhysicsBody2D<class_PhysicsBody2D>` **<** :ref:`CollisionObject2D<class_CollisionObject2D>` **<** :ref:`Node2D<class_Node2D>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
|
|
|
|
Un cuerpo de física 2D especializado para characters movidos por script.
|
|
|
|
.. rst-class:: classref-introduction-group
|
|
|
|
Descripción
|
|
----------------------
|
|
|
|
**CharacterBody2D** es una clase especializada para cuerpos físicos diseñados para ser controlados por el usuario. No están afectados por la física en absoluto, pero sí afectan a otros cuerpos físicos en su trayectoria. Principalmente, se utilizan para proporcionar una API de alto nivel que permite mover objetos con detección de paredes y pendientes (método :ref:`move_and_slide()<class_CharacterBody2D_method_move_and_slide>`), además de la detección general de colisiones que ofrece :ref:`PhysicsBody2D.move_and_collide()<class_PhysicsBody2D_method_move_and_collide>`. Esto los hace útiles para cuerpos físicos altamente configurables que deben moverse de maneras específicas y colisionar con el mundo, como suele ser el caso de los personajes controlados por el usuario.
|
|
|
|
Para los objetos del juego que no requieren un movimiento complejo ni detección de colisiones, como plataformas móviles, :ref:`AnimatableBody2D<class_AnimatableBody2D>` es más sencillo de configurar.
|
|
|
|
.. rst-class:: classref-introduction-group
|
|
|
|
Tutoriales
|
|
--------------------
|
|
|
|
- :doc:`Introducción a la física <../tutorials/physics/physics_introduction>`
|
|
|
|
- :doc:`Solución de problemas de física <../tutorials/physics/troubleshooting_physics_issues>`
|
|
|
|
- :doc:`Personaje cinemático (2D) <../tutorials/physics/kinematic_character_2d>`
|
|
|
|
- :doc:`Usar CharacterBody2D <../tutorials/physics/using_character_body_2d>`
|
|
|
|
- `Demo de Personaje Cinemático en 2D <https://godotengine.org/asset-library/asset/2719>`__
|
|
|
|
- `Demo de Plataformas en 2D <https://godotengine.org/asset-library/asset/2727>`__
|
|
|
|
.. rst-class:: classref-reftable-group
|
|
|
|
Propiedades
|
|
----------------------
|
|
|
|
.. 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.7853982`` |
|
|
+--------------------------------------------------------------+------------------------------------------------------------------------------------+--------------------+
|
|
| :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.2617994`` |
|
|
+--------------------------------------------------------------+------------------------------------------------------------------------------------+--------------------+
|
|
|
|
.. rst-class:: classref-reftable-group
|
|
|
|
Métodos
|
|
--------------
|
|
|
|
.. 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>`\ (\ up_direction\: :ref:`Vector2<class_Vector2>` = 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>`\ (\ slide_idx\: :ref:`int<class_int>`\ ) |
|
|
+---------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :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
|
|
|
|
Enumeraciones
|
|
--------------------------
|
|
|
|
.. _enum_CharacterBody2D_MotionMode:
|
|
|
|
.. rst-class:: classref-enumeration
|
|
|
|
enum **MotionMode**: :ref:`🔗<enum_CharacterBody2D_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**: :ref:`🔗<enum_CharacterBody2D_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``
|
|
|
|
No hacer nada al salir de una plataforma.
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-descriptions-group
|
|
|
|
Descripciones de Propiedades
|
|
--------------------------------------------------------
|
|
|
|
.. _class_CharacterBody2D_property_floor_block_on_wall:
|
|
|
|
.. rst-class:: classref-property
|
|
|
|
:ref:`bool<class_bool>` **floor_block_on_wall** = ``true`` :ref:`🔗<class_CharacterBody2D_property_floor_block_on_wall>`
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- |void| **set_floor_block_on_wall_enabled**\ (\ value\: :ref:`bool<class_bool>`\ )
|
|
- :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`` :ref:`🔗<class_CharacterBody2D_property_floor_constant_speed>`
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- |void| **set_floor_constant_speed_enabled**\ (\ value\: :ref:`bool<class_bool>`\ )
|
|
- :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.7853982`` :ref:`🔗<class_CharacterBody2D_property_floor_max_angle>`
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- |void| **set_floor_max_angle**\ (\ value\: :ref:`float<class_float>`\ )
|
|
- :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`` :ref:`🔗<class_CharacterBody2D_property_floor_snap_length>`
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- |void| **set_floor_snap_length**\ (\ value\: :ref:`float<class_float>`\ )
|
|
- :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`` :ref:`🔗<class_CharacterBody2D_property_floor_stop_on_slope>`
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- |void| **set_floor_stop_on_slope_enabled**\ (\ value\: :ref:`bool<class_bool>`\ )
|
|
- :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`` :ref:`🔗<class_CharacterBody2D_property_max_slides>`
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- |void| **set_max_slides**\ (\ value\: :ref:`int<class_int>`\ )
|
|
- :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>`. Must be greater than zero.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_CharacterBody2D_property_motion_mode:
|
|
|
|
.. rst-class:: classref-property
|
|
|
|
:ref:`MotionMode<enum_CharacterBody2D_MotionMode>` **motion_mode** = ``0`` :ref:`🔗<class_CharacterBody2D_property_motion_mode>`
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- |void| **set_motion_mode**\ (\ value\: :ref:`MotionMode<enum_CharacterBody2D_MotionMode>`\ )
|
|
- :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>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_CharacterBody2D_property_platform_floor_layers:
|
|
|
|
.. rst-class:: classref-property
|
|
|
|
:ref:`int<class_int>` **platform_floor_layers** = ``4294967295`` :ref:`🔗<class_CharacterBody2D_property_platform_floor_layers>`
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- |void| **set_platform_floor_layers**\ (\ value\: :ref:`int<class_int>`\ )
|
|
- :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`` :ref:`🔗<class_CharacterBody2D_property_platform_on_leave>`
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- |void| **set_platform_on_leave**\ (\ value\: :ref:`PlatformOnLeave<enum_CharacterBody2D_PlatformOnLeave>`\ )
|
|
- :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.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_CharacterBody2D_property_platform_wall_layers:
|
|
|
|
.. rst-class:: classref-property
|
|
|
|
:ref:`int<class_int>` **platform_wall_layers** = ``0`` :ref:`🔗<class_CharacterBody2D_property_platform_wall_layers>`
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- |void| **set_platform_wall_layers**\ (\ value\: :ref:`int<class_int>`\ )
|
|
- :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`` :ref:`🔗<class_CharacterBody2D_property_safe_margin>`
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- |void| **set_safe_margin**\ (\ value\: :ref:`float<class_float>`\ )
|
|
- :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`` :ref:`🔗<class_CharacterBody2D_property_slide_on_ceiling>`
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- |void| **set_slide_on_ceiling_enabled**\ (\ value\: :ref:`bool<class_bool>`\ )
|
|
- :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)`` :ref:`🔗<class_CharacterBody2D_property_up_direction>`
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- |void| **set_up_direction**\ (\ value\: :ref:`Vector2<class_Vector2>`\ )
|
|
- :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)`` :ref:`🔗<class_CharacterBody2D_property_velocity>`
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- |void| **set_velocity**\ (\ value\: :ref:`Vector2<class_Vector2>`\ )
|
|
- :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>`.
|
|
|
|
\ **Note:** A common mistake is setting this property to the desired velocity multiplied by ``delta``, which produces a motion vector in pixels.
|
|
|
|
.. 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.2617994`` :ref:`🔗<class_CharacterBody2D_property_wall_min_slide_angle>`
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- |void| **set_wall_min_slide_angle**\ (\ value\: :ref:`float<class_float>`\ )
|
|
- :ref:`float<class_float>` **get_wall_min_slide_angle**\ (\ )
|
|
|
|
Minimum angle (in radians) where the body is allowed to slide when it encounters a wall. 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
|
|
|
|
Descripciones de Métodos
|
|
------------------------------------------------
|
|
|
|
.. _class_CharacterBody2D_method_apply_floor_snap:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
|void| **apply_floor_snap**\ (\ ) :ref:`🔗<class_CharacterBody2D_method_apply_floor_snap>`
|
|
|
|
Permite aplicar manualmente un ajuste al suelo sin importar la velocidad del cuerpo. Esta función no hace nada cuando :ref:`is_on_floor()<class_CharacterBody2D_method_is_on_floor>` devuelve ``true``.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_CharacterBody2D_method_get_floor_angle:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`float<class_float>` **get_floor_angle**\ (\ up_direction\: :ref:`Vector2<class_Vector2>` = Vector2(0, -1)\ ) |const| :ref:`🔗<class_CharacterBody2D_method_get_floor_angle>`
|
|
|
|
Devuelve el ángulo de colisión del suelo en el último punto de colisión según ``up_direction``, que es :ref:`Vector2.UP<class_Vector2_constant_UP>` por defecto. Este valor es siempre positivo y solo es válido después de llamar a :ref:`move_and_slide()<class_CharacterBody2D_method_move_and_slide>` y cuando :ref:`is_on_floor()<class_CharacterBody2D_method_is_on_floor>` devuelve ``true``.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_CharacterBody2D_method_get_floor_normal:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`Vector2<class_Vector2>` **get_floor_normal**\ (\ ) |const| :ref:`🔗<class_CharacterBody2D_method_get_floor_normal>`
|
|
|
|
Devuelve la normal de colisión del suelo en el último punto de colisión. Sólo es válido después de llamar a :ref:`move_and_slide()<class_CharacterBody2D_method_move_and_slide>` y cuando :ref:`is_on_floor()<class_CharacterBody2D_method_is_on_floor>` devuelve ``true``.
|
|
|
|
\ **Advertencia:** La normal de colisión no siempre es la misma que la normal de la superficie.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_CharacterBody2D_method_get_last_motion:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`Vector2<class_Vector2>` **get_last_motion**\ (\ ) |const| :ref:`🔗<class_CharacterBody2D_method_get_last_motion>`
|
|
|
|
Devuelve el último movimiento aplicado al **CharacterBody2D** durante la última llamada a :ref:`move_and_slide()<class_CharacterBody2D_method_move_and_slide>`. El movimiento se puede dividir en múltiples movimientos cuando se produce un deslizamiento, y este método devuelve el último, que es útil para recuperar la dirección actual del movimiento.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_CharacterBody2D_method_get_last_slide_collision:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`KinematicCollision2D<class_KinematicCollision2D>` **get_last_slide_collision**\ (\ ) :ref:`🔗<class_CharacterBody2D_method_get_last_slide_collision>`
|
|
|
|
Returns a :ref:`KinematicCollision2D<class_KinematicCollision2D>` if a collision occurred. The returned value contains information about the latest collision that occurred during the last call to :ref:`move_and_slide()<class_CharacterBody2D_method_move_and_slide>`. Returns ``null`` if no collision occurred. See also :ref:`get_slide_collision()<class_CharacterBody2D_method_get_slide_collision>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_CharacterBody2D_method_get_platform_velocity:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`Vector2<class_Vector2>` **get_platform_velocity**\ (\ ) |const| :ref:`🔗<class_CharacterBody2D_method_get_platform_velocity>`
|
|
|
|
Devuelve la velocidad lineal de la plataforma en el último punto de colisión. Solo es válido después de llamar a :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| :ref:`🔗<class_CharacterBody2D_method_get_position_delta>`
|
|
|
|
Devuelve el recorrido (posición delta) que se produjo durante la última llamada a :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| :ref:`🔗<class_CharacterBody2D_method_get_real_velocity>`
|
|
|
|
Devuelve la velocidad real actual desde la última llamada a :ref:`move_and_slide()<class_CharacterBody2D_method_move_and_slide>`. Por ejemplo, al subir una pendiente, te moverás en diagonal aunque la velocidad sea horizontal. Este método devuelve el movimiento diagonal, a diferencia de :ref:`velocity<class_CharacterBody2D_property_velocity>` que devuelve la velocidad solicitada.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_CharacterBody2D_method_get_slide_collision:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`KinematicCollision2D<class_KinematicCollision2D>` **get_slide_collision**\ (\ slide_idx\: :ref:`int<class_int>`\ ) :ref:`🔗<class_CharacterBody2D_method_get_slide_collision>`
|
|
|
|
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). See also :ref:`get_last_slide_collision()<class_CharacterBody2D_method_get_last_slide_collision>`.
|
|
|
|
\ **Example:** Iterate through the collisions with a ``for`` loop:
|
|
|
|
|
|
.. 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| :ref:`🔗<class_CharacterBody2D_method_get_slide_collision_count>`
|
|
|
|
Devuelve el número de veces que el cuerpo chocó y cambió de dirección durante la última llamada a :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| :ref:`🔗<class_CharacterBody2D_method_get_wall_normal>`
|
|
|
|
Devuelve la normal de la colisión de la pared en el último punto de colisión. Solo es válido después de llamar a :ref:`move_and_slide()<class_CharacterBody2D_method_move_and_slide>` y cuando :ref:`is_on_wall()<class_CharacterBody2D_method_is_on_wall>` devuelve ``true``.
|
|
|
|
\ **Advertencia:** La normal de colisión no siempre es la misma que la normal de la superficie.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_CharacterBody2D_method_is_on_ceiling:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`bool<class_bool>` **is_on_ceiling**\ (\ ) |const| :ref:`🔗<class_CharacterBody2D_method_is_on_ceiling>`
|
|
|
|
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| :ref:`🔗<class_CharacterBody2D_method_is_on_ceiling_only>`
|
|
|
|
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| :ref:`🔗<class_CharacterBody2D_method_is_on_floor>`
|
|
|
|
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| :ref:`🔗<class_CharacterBody2D_method_is_on_floor_only>`
|
|
|
|
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| :ref:`🔗<class_CharacterBody2D_method_is_on_wall>`
|
|
|
|
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| :ref:`🔗<class_CharacterBody2D_method_is_on_wall_only>`
|
|
|
|
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**\ (\ ) :ref:`🔗<class_CharacterBody2D_method_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.
|
|
|
|
This method should be used in :ref:`Node._physics_process()<class_Node_private_method__physics_process>` (or in a method called by :ref:`Node._physics_process()<class_Node_private_method__physics_process>`), as it uses the physics step's ``delta`` value automatically in calculations. Otherwise, the simulation will run at an incorrect speed.
|
|
|
|
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 (Normalmente, este método debería ser sobreescrito por el usuario para que tenga algún efecto.)`
|
|
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
|
|
.. |const| replace:: :abbr:`const (Este método no tiene efectos secundarios. No modifica ninguna de las variables miembro de la instancia.)`
|
|
.. |vararg| replace:: :abbr:`vararg (Este método permite agregar cualquier número de argumentos después de los descritos aquí.)`
|
|
.. |constructor| replace:: :abbr:`constructor (Este método se utiliza para construir un tipo.)`
|
|
.. |static| replace:: :abbr:`static (Este método no necesita una instancia para ser llamado, por lo que puede llamarse directamente utilizando el nombre de la clase.)`
|
|
.. |operator| replace:: :abbr:`operator (Este método describe un operador válido para usar con este tipo como operando izquierdo.)`
|
|
.. |bitfield| replace:: :abbr:`BitField (Este valor es un entero compuesto como una máscara de bits de las siguientes banderas.)`
|
|
.. |void| replace:: :abbr:`void (Sin valor de retorno.)`
|