Files
godot-docs-l10n/classes/es/class_kinematicbody2d.rst
Rémi Verschelde cf78697eea Add localized class reference as pre-generated RST files
Currently including `zh_CN` and `es` which both have very high completion
ratios. Others will be added once they reach a significant percentage too.

These RST files will be used by godot-docs in place of its `classes` folder
after we sync with https://github.com/godotengine/godot-docs/pull/5458.

The update workflow is manual for now (example for `zh_CN`):

- Build `godotengine/godot` in the branch we currently track (now `3.x`)
- Run `godot --doctool -l zh_CN`
- Run `cd doc && make rst LANGARG=zh_CN`
- Copy `doc/_build/rst/*` to `classes/zh_CN/` here
- Make sure to have `classes/zh_CN/index.rst` copied from `docs/classes`
2021-12-21 16:07:55 +01:00

253 lines
27 KiB
ReStructuredText

:github_url: hide
.. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
.. DO NOT EDIT THIS FILE, but the KinematicBody2D.xml source instead.
.. The source is found in doc/classes or modules/<name>/doc_classes.
.. _class_KinematicBody2D:
KinematicBody2D
===============
**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>`
Nodo 2D del cuerpo cinético.
Descripción
----------------------
Kinematic bodies are special types of bodies that are meant to be user-controlled. They are not affected by physics at all; to other types of bodies, such as a character or a rigid body, these are the same as a static body. However, they have two main uses:
\ **Simulated motion:** When these bodies are moved manually, either from code or from an :ref:`AnimationPlayer<class_AnimationPlayer>` (with :ref:`AnimationPlayer.playback_process_mode<class_AnimationPlayer_property_playback_process_mode>` set to "physics"), the physics will automatically compute an estimate of their linear and angular velocity. This makes them very useful for moving platforms or other AnimationPlayer-controlled objects (like a door, a bridge that opens, etc).
\ **Kinematic characters:** KinematicBody2D also has an API for moving objects (the :ref:`move_and_collide<class_KinematicBody2D_method_move_and_collide>` and :ref:`move_and_slide<class_KinematicBody2D_method_move_and_slide>` methods) while performing collision tests. This makes them really useful to implement characters that collide against a world, but don't require advanced physics.
Tutoriales
--------------------
- :doc:`Kinematic character (2D) <../tutorials/physics/kinematic_character_2d>`
- :doc:`Using KinematicBody2D <../tutorials/physics/using_kinematic_body_2d>`
- `2D Kinematic Character Demo <https://godotengine.org/asset-library/asset/113>`__
- `2D Platformer Demo <https://godotengine.org/asset-library/asset/120>`__
Propiedades
----------------------
+---------------------------+--------------------------------------------------------------------------------------+-----------+
| :ref:`float<class_float>` | :ref:`collision/safe_margin<class_KinematicBody2D_property_collision/safe_margin>` | ``0.08`` |
+---------------------------+--------------------------------------------------------------------------------------+-----------+
| :ref:`bool<class_bool>` | :ref:`motion/sync_to_physics<class_KinematicBody2D_property_motion/sync_to_physics>` | ``false`` |
+---------------------------+--------------------------------------------------------------------------------------+-----------+
Métodos
--------------
+---------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`get_floor_angle<class_KinematicBody2D_method_get_floor_angle>` **(** :ref:`Vector2<class_Vector2>` up_direction=Vector2( 0, -1 ) **)** |const| |
+---------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`get_floor_normal<class_KinematicBody2D_method_get_floor_normal>` **(** **)** |const| |
+---------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`get_floor_velocity<class_KinematicBody2D_method_get_floor_velocity>` **(** **)** |const| |
+---------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`KinematicCollision2D<class_KinematicCollision2D>` | :ref:`get_last_slide_collision<class_KinematicBody2D_method_get_last_slide_collision>` **(** **)** |
+---------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`KinematicCollision2D<class_KinematicCollision2D>` | :ref:`get_slide_collision<class_KinematicBody2D_method_get_slide_collision>` **(** :ref:`int<class_int>` slide_idx **)** |
+---------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`get_slide_count<class_KinematicBody2D_method_get_slide_count>` **(** **)** |const| |
+---------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`is_on_ceiling<class_KinematicBody2D_method_is_on_ceiling>` **(** **)** |const| |
+---------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`is_on_floor<class_KinematicBody2D_method_is_on_floor>` **(** **)** |const| |
+---------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`is_on_wall<class_KinematicBody2D_method_is_on_wall>` **(** **)** |const| |
+---------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`KinematicCollision2D<class_KinematicCollision2D>` | :ref:`move_and_collide<class_KinematicBody2D_method_move_and_collide>` **(** :ref:`Vector2<class_Vector2>` rel_vec, :ref:`bool<class_bool>` infinite_inertia=true, :ref:`bool<class_bool>` exclude_raycast_shapes=true, :ref:`bool<class_bool>` test_only=false **)** |
+---------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`move_and_slide<class_KinematicBody2D_method_move_and_slide>` **(** :ref:`Vector2<class_Vector2>` linear_velocity, :ref:`Vector2<class_Vector2>` up_direction=Vector2( 0, 0 ), :ref:`bool<class_bool>` stop_on_slope=false, :ref:`int<class_int>` max_slides=4, :ref:`float<class_float>` floor_max_angle=0.785398, :ref:`bool<class_bool>` infinite_inertia=true **)** |
+---------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`move_and_slide_with_snap<class_KinematicBody2D_method_move_and_slide_with_snap>` **(** :ref:`Vector2<class_Vector2>` linear_velocity, :ref:`Vector2<class_Vector2>` snap, :ref:`Vector2<class_Vector2>` up_direction=Vector2( 0, 0 ), :ref:`bool<class_bool>` stop_on_slope=false, :ref:`int<class_int>` max_slides=4, :ref:`float<class_float>` floor_max_angle=0.785398, :ref:`bool<class_bool>` infinite_inertia=true **)** |
+---------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`test_move<class_KinematicBody2D_method_test_move>` **(** :ref:`Transform2D<class_Transform2D>` from, :ref:`Vector2<class_Vector2>` rel_vec, :ref:`bool<class_bool>` infinite_inertia=true **)** |
+---------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Descripciones de Propiedades
--------------------------------------------------------
.. _class_KinematicBody2D_property_collision/safe_margin:
- :ref:`float<class_float>` **collision/safe_margin**
+-----------+------------------------+
| *Default* | ``0.08`` |
+-----------+------------------------+
| *Setter* | set_safe_margin(value) |
+-----------+------------------------+
| *Getter* | get_safe_margin() |
+-----------+------------------------+
Extra margin used for collision recovery in motion functions (see :ref:`move_and_collide<class_KinematicBody2D_method_move_and_collide>`, :ref:`move_and_slide<class_KinematicBody2D_method_move_and_slide>`, :ref:`move_and_slide_with_snap<class_KinematicBody2D_method_move_and_slide_with_snap>`).
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 kinematic bodies.
----
.. _class_KinematicBody2D_property_motion/sync_to_physics:
- :ref:`bool<class_bool>` **motion/sync_to_physics**
+-----------+------------------------------+
| *Default* | ``false`` |
+-----------+------------------------------+
| *Setter* | set_sync_to_physics(value) |
+-----------+------------------------------+
| *Getter* | is_sync_to_physics_enabled() |
+-----------+------------------------------+
Si ``true``, el movimiento del cuerpo se sincronizará con el marco de la física. Esto es útil cuando se anima el movimiento a través de :ref:`AnimationPlayer<class_AnimationPlayer>`, por ejemplo en plataformas móviles. No uses **not** junto con las funciones :ref:`move_and_slide<class_KinematicBody2D_method_move_and_slide>` o :ref:`move_and_collide<class_KinematicBody2D_method_move_and_collide>`.
Descripciones de Métodos
------------------------------------------------
.. _class_KinematicBody2D_method_get_floor_angle:
- :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 ``Vector2.UP`` by default. This value is always positive and only valid after calling :ref:`move_and_slide<class_KinematicBody2D_method_move_and_slide>` and when :ref:`is_on_floor<class_KinematicBody2D_method_is_on_floor>` returns ``true``.
----
.. _class_KinematicBody2D_method_get_floor_normal:
- :ref:`Vector2<class_Vector2>` **get_floor_normal** **(** **)** |const|
Devuelve la normal de la superficie del suelo en el último punto de colisión. Sólo válido después de llamar a :ref:`move_and_slide<class_KinematicBody2D_method_move_and_slide>` o :ref:`move_and_slide_with_snap<class_KinematicBody2D_method_move_and_slide_with_snap>` y cuando :ref:`is_on_floor<class_KinematicBody2D_method_is_on_floor>` devuelve ``true``.
----
.. _class_KinematicBody2D_method_get_floor_velocity:
- :ref:`Vector2<class_Vector2>` **get_floor_velocity** **(** **)** |const|
Devuelve la velocidad lineal del suelo en el último punto de colisión. Sólo es válido después de llamar a :ref:`move_and_slide<class_KinematicBody2D_method_move_and_slide>` o :ref:`move_and_slide_with_snap<class_KinematicBody2D_method_move_and_slide_with_snap>` y cuando :ref:`is_on_floor<class_KinematicBody2D_method_is_on_floor>` devuelve ``true``.
----
.. _class_KinematicBody2D_method_get_last_slide_collision:
- :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_KinematicBody2D_method_move_and_slide>`.
----
.. _class_KinematicBody2D_method_get_slide_collision:
- :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_KinematicBody2D_method_move_and_slide>` or :ref:`move_and_slide_with_snap<class_KinematicBody2D_method_move_and_slide_with_snap>`. Since the body can collide several times in a single call to :ref:`move_and_slide<class_KinematicBody2D_method_move_and_slide>`, you must specify the index of the collision in the range 0 to (:ref:`get_slide_count<class_KinematicBody2D_method_get_slide_count>` - 1).
\ **Example usage:**\
::
for i in get_slide_count():
var collision = get_slide_collision(i)
print("Collided with: ", collision.collider.name)
----
.. _class_KinematicBody2D_method_get_slide_count:
- :ref:`int<class_int>` **get_slide_count** **(** **)** |const|
Returns the number of times the body collided and changed direction during the last call to :ref:`move_and_slide<class_KinematicBody2D_method_move_and_slide>` or :ref:`move_and_slide_with_snap<class_KinematicBody2D_method_move_and_slide_with_snap>`.
----
.. _class_KinematicBody2D_method_is_on_ceiling:
- :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_KinematicBody2D_method_move_and_slide>` or :ref:`move_and_slide_with_snap<class_KinematicBody2D_method_move_and_slide_with_snap>`. Otherwise, returns ``false``.
----
.. _class_KinematicBody2D_method_is_on_floor:
- :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_KinematicBody2D_method_move_and_slide>` or :ref:`move_and_slide_with_snap<class_KinematicBody2D_method_move_and_slide_with_snap>`. Otherwise, returns ``false``.
----
.. _class_KinematicBody2D_method_is_on_wall:
- :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_KinematicBody2D_method_move_and_slide>` or :ref:`move_and_slide_with_snap<class_KinematicBody2D_method_move_and_slide_with_snap>`. Otherwise, returns ``false``.
----
.. _class_KinematicBody2D_method_move_and_collide:
- :ref:`KinematicCollision2D<class_KinematicCollision2D>` **move_and_collide** **(** :ref:`Vector2<class_Vector2>` rel_vec, :ref:`bool<class_bool>` infinite_inertia=true, :ref:`bool<class_bool>` exclude_raycast_shapes=true, :ref:`bool<class_bool>` test_only=false **)**
Moves the body along the vector ``rel_vec``. The body will stop if it collides. Returns a :ref:`KinematicCollision2D<class_KinematicCollision2D>`, which contains information about the collision when stopped, or when touching another body along the motion.
If ``test_only`` is ``true``, the body does not move but the would-be collision information is given.
----
.. _class_KinematicBody2D_method_move_and_slide:
- :ref:`Vector2<class_Vector2>` **move_and_slide** **(** :ref:`Vector2<class_Vector2>` linear_velocity, :ref:`Vector2<class_Vector2>` up_direction=Vector2( 0, 0 ), :ref:`bool<class_bool>` stop_on_slope=false, :ref:`int<class_int>` max_slides=4, :ref:`float<class_float>` floor_max_angle=0.785398, :ref:`bool<class_bool>` infinite_inertia=true **)**
Mueve el cuerpo a lo largo de un vector. Si el cuerpo choca con otro, se deslizará a lo largo del otro cuerpo en lugar de detenerse inmediatamente. Si el otro cuerpo es un ``KinematicBody2D`` o un :ref:`RigidBody2D<class_RigidBody2D>`, también se verá afectado por el movimiento del otro cuerpo. Puedes usar esto para hacer plataformas móviles o giratorias, o para hacer que los nodos empujen a otros nodos.
Este método debe ser usado en :ref:`Node._physics_process<class_Node_method__physics_process>` (o en un método llamado por :ref:`Node._physics_process<class_Node_method__physics_process>`), ya que usa el valor del paso de física ``delta`` automáticamente en los cálculos. De lo contrario, la simulación se ejecutará a una velocidad incorrecta.
\ ``linear_velocity`` es el vector de velocidad en píxeles por segundo. A diferencia del :ref:`move_and_collide<class_KinematicBody2D_method_move_and_collide>`, debes *no* multiplicarlo por ``delta`` - el motor de física se encarga de aplicar la velocidad.
\ ``up_direction`` es la dirección hacia arriba, usada para determinar qué es una pared y qué es un piso o un techo. Si se establece el valor por defecto de ``Vector2(0, 0)``, todo se considera una pared. Esto es útil para los juegos de arriba hacia abajo.
Si ``stop_on_slope`` es ``true``, el cuerpo no se deslizará por las pendientes cuando incluyas la gravedad en ``linear_velocity`` y el cuerpo se quede quieto.
Si el cuerpo colisiona, cambiará de dirección un máximo de ``max_slides`` veces antes de detenerse.
\ ``floor_max_angle`` es el ángulo máximo (en radianes) en el que una pendiente se considera todavía un suelo (o un techo), en lugar de una pared. El valor por defecto es igual a 45 grados.
Si ``infinite_inertia`` es ``true``, el cuerpo podrá empujar los nodos de :ref:`RigidBody2D<class_RigidBody2D>`, pero no detectará ninguna colisión con ellos. Si ``false``, interactuará con los nodos de :ref:`RigidBody2D<class_RigidBody2D>` como con :ref:`StaticBody2D<class_StaticBody2D>`.
Devuelve el vector ``linear_velocity``, rotado y/o escalado si se produjo una colisión de deslizamiento. Para obtener información detallada sobre las colisiones ocurridas, usa :ref:`get_slide_collision<class_KinematicBody2D_method_get_slide_collision>`.
----
.. _class_KinematicBody2D_method_move_and_slide_with_snap:
- :ref:`Vector2<class_Vector2>` **move_and_slide_with_snap** **(** :ref:`Vector2<class_Vector2>` linear_velocity, :ref:`Vector2<class_Vector2>` snap, :ref:`Vector2<class_Vector2>` up_direction=Vector2( 0, 0 ), :ref:`bool<class_bool>` stop_on_slope=false, :ref:`int<class_int>` max_slides=4, :ref:`float<class_float>` floor_max_angle=0.785398, :ref:`bool<class_bool>` infinite_inertia=true **)**
Mueve el cuerpo mientras lo mantiene unido a las laderas. Similar al :ref:`move_and_slide<class_KinematicBody2D_method_move_and_slide>`.
Mientras el vector ``snap`` esté en contacto con el suelo, el cuerpo permanecerá unido a la superficie. Esto significa que debes desactivar el snap para poder saltar, por ejemplo. Puedes hacerlo poniendo ``snap`` en ``(0, 0)`` o usando :ref:`move_and_slide<class_KinematicBody2D_method_move_and_slide>` en su lugar.
----
.. _class_KinematicBody2D_method_test_move:
- :ref:`bool<class_bool>` **test_move** **(** :ref:`Transform2D<class_Transform2D>` from, :ref:`Vector2<class_Vector2>` rel_vec, :ref:`bool<class_bool>` infinite_inertia=true **)**
Checks for collisions without moving the body. Virtually sets the node's position, scale and rotation to that of the given :ref:`Transform2D<class_Transform2D>`, then tries to move the body along the vector ``rel_vec``. Returns ``true`` if a collision would stop the body from moving along the whole path.
Use :ref:`move_and_collide<class_KinematicBody2D_method_move_and_collide>` instead for detecting collision with touching bodies.
.. |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.)`