class_kinematicbody2d.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the doc/base/classes.xml source instead.
  3. .. _class_KinematicBody2D:
  4. KinematicBody2D
  5. ===============
  6. **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>`
  7. **Category:** Core
  8. Brief Description
  9. -----------------
  10. Kinematic body 2D node.
  11. Member Functions
  12. ----------------
  13. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
  14. | :ref:`Variant<class_variant>` | :ref:`get_collider<class_KinematicBody2D_get_collider>` **(** **)** const |
  15. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
  16. | :ref:`Variant<class_variant>` | :ref:`get_collider_metadata<class_KinematicBody2D_get_collider_metadata>` **(** **)** const |
  17. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
  18. | :ref:`int<class_int>` | :ref:`get_collider_shape<class_KinematicBody2D_get_collider_shape>` **(** **)** const |
  19. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
  20. | :ref:`Vector2<class_vector2>` | :ref:`get_collider_velocity<class_KinematicBody2D_get_collider_velocity>` **(** **)** const |
  21. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`float<class_float>` | :ref:`get_collision_margin<class_KinematicBody2D_get_collision_margin>` **(** **)** const |
  23. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`Vector2<class_vector2>` | :ref:`get_collision_normal<class_KinematicBody2D_get_collision_normal>` **(** **)** const |
  25. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`Vector2<class_vector2>` | :ref:`get_collision_pos<class_KinematicBody2D_get_collision_pos>` **(** **)** const |
  27. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`Vector2<class_vector2>` | :ref:`get_travel<class_KinematicBody2D_get_travel>` **(** **)** const |
  29. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`bool<class_bool>` | :ref:`is_colliding<class_KinematicBody2D_is_colliding>` **(** **)** const |
  31. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`Vector2<class_vector2>` | :ref:`move<class_KinematicBody2D_move>` **(** :ref:`Vector2<class_vector2>` rel_vec **)** |
  33. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`Vector2<class_vector2>` | :ref:`move_to<class_KinematicBody2D_move_to>` **(** :ref:`Vector2<class_vector2>` position **)** |
  35. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | void | :ref:`revert_motion<class_KinematicBody2D_revert_motion>` **(** **)** |
  37. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | void | :ref:`set_collision_margin<class_KinematicBody2D_set_collision_margin>` **(** :ref:`float<class_float>` pixels **)** |
  39. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`bool<class_bool>` | :ref:`test_move<class_KinematicBody2D_test_move>` **(** :ref:`Vector2<class_vector2>` rel_vec **)** |
  41. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`bool<class_bool>` | :ref:`test_move_from<class_KinematicBody2D_test_move_from>` **(** :ref:`Matrix32<class_matrix32>` from, :ref:`Vector2<class_vector2>` rel_vec **)** |
  43. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. Description
  45. -----------
  46. 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 a character or a rigid body, these are the same as a static body). They have however, two main uses:
  47. Simulated Motion: When these bodies are moved manually, either from code or from an AnimationPlayer (with process mode set to fixed), 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).
  48. Kinematic Characters: KinematicBody2D also has an api for moving objects (the :ref:`move<class_KinematicBody2D_move>` method) while performing collision tests. This makes them really useful to implement characters that collide against a world, but that don't require advanced physics.
  49. Member Function Description
  50. ---------------------------
  51. .. _class_KinematicBody2D_get_collider:
  52. - :ref:`Variant<class_variant>` **get_collider** **(** **)** const
  53. Return the body that collided with this one.
  54. .. _class_KinematicBody2D_get_collider_metadata:
  55. - :ref:`Variant<class_variant>` **get_collider_metadata** **(** **)** const
  56. Return the metadata of the shape that collided with this body. If there is no collision, it will return 0, so collisions must be checked first with :ref:`is_colliding<class_KinematicBody2D_is_colliding>`. Additionally, this metadata can not be set with :ref:`Object.set_meta<class_Object_set_meta>`, it must be set with :ref:`Physics2DServer.body_set_shape_metadata<class_Physics2DServer_body_set_shape_metadata>`.
  57. .. _class_KinematicBody2D_get_collider_shape:
  58. - :ref:`int<class_int>` **get_collider_shape** **(** **)** const
  59. Return the shape index from the body that collided with this one. If there is no collision, this method will return 0, so collisions must be checked first with :ref:`is_colliding<class_KinematicBody2D_is_colliding>`.
  60. .. _class_KinematicBody2D_get_collider_velocity:
  61. - :ref:`Vector2<class_vector2>` **get_collider_velocity** **(** **)** const
  62. Return the velocity of the body that collided with this one.
  63. .. _class_KinematicBody2D_get_collision_margin:
  64. - :ref:`float<class_float>` **get_collision_margin** **(** **)** const
  65. Return the collision margin for this object.
  66. .. _class_KinematicBody2D_get_collision_normal:
  67. - :ref:`Vector2<class_vector2>` **get_collision_normal** **(** **)** const
  68. Return the normal of the surface the body collided with. This is useful to implement sliding along a surface.
  69. .. _class_KinematicBody2D_get_collision_pos:
  70. - :ref:`Vector2<class_vector2>` **get_collision_pos** **(** **)** const
  71. Return the point in space where the body is touching another. If there is no collision, this method will return (0,0), so collisions must be checked first with :ref:`is_colliding<class_KinematicBody2D_is_colliding>`.
  72. .. _class_KinematicBody2D_get_travel:
  73. - :ref:`Vector2<class_vector2>` **get_travel** **(** **)** const
  74. Return the last movement done by the body.
  75. .. _class_KinematicBody2D_is_colliding:
  76. - :ref:`bool<class_bool>` **is_colliding** **(** **)** const
  77. Return whether the body is colliding with another.
  78. .. _class_KinematicBody2D_move:
  79. - :ref:`Vector2<class_vector2>` **move** **(** :ref:`Vector2<class_vector2>` rel_vec **)**
  80. Move the body in the given direction, stopping if there is an obstacle. The returned vector is how much movement was remaining before being stopped.
  81. .. _class_KinematicBody2D_move_to:
  82. - :ref:`Vector2<class_vector2>` **move_to** **(** :ref:`Vector2<class_vector2>` position **)**
  83. Move the body to the given position. This is not a teleport, and the body will stop if there is an obstacle. The returned vector is how much movement was remaining before being stopped.
  84. .. _class_KinematicBody2D_revert_motion:
  85. - void **revert_motion** **(** **)**
  86. Undo the last movement done by the body.
  87. .. _class_KinematicBody2D_set_collision_margin:
  88. - void **set_collision_margin** **(** :ref:`float<class_float>` pixels **)**
  89. Set the collision margin for this object. A collision margin is an amount (in pixels) that all shapes will grow when computing collisions, to account for numerical imprecision.
  90. .. _class_KinematicBody2D_test_move:
  91. - :ref:`bool<class_bool>` **test_move** **(** :ref:`Vector2<class_vector2>` rel_vec **)**
  92. Return true if there would be a collision if the body moved in the given direction.
  93. .. _class_KinematicBody2D_test_move_from:
  94. - :ref:`bool<class_bool>` **test_move_from** **(** :ref:`Matrix32<class_matrix32>` from, :ref:`Vector2<class_vector2>` rel_vec **)**