RigidBody2D.xml 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="RigidBody2D" inherits="PhysicsBody2D" category="Core" version="3.0.alpha.custom_build">
  3. <brief_description>
  4. A body that is controlled by the 2D physics engine.
  5. </brief_description>
  6. <description>
  7. This node implements simulated 2D physics. You do not control a RigidBody2D directly. Instead you apply forces to it (gravity, impulses, etc.) and the physics simulation calculates the resulting movement based on its mass, friction, and other physical properties.
  8. A RigidBody2D has 4 behavior modes (see [member mode]):
  9. - [b]Rigid[/b]: The body behaves as a physical object. It collides with other bodies and responds to forces applied to it. This is the default mode.
  10. - [b]Static[/b]: The body behaves like a [StaticBody2D] and does not move.
  11. - [b]Character[/b]: Similar to [code]Rigid[/code] mode, but the body can not rotate.
  12. - [b]Kinematic[/b]: The body behaves like a [KinematicBody2D], and must be moved by code.
  13. [b]Note:[/b] You should not change a RigidBody2D's [code]position[/code] or [code]linear_velocity[/code] every frame or even very often. If you need to directly affect the body's state, use [method _integrate_forces], which allows you to directly access the physics state.
  14. If you need to override the default physics behavior, you can write a custom force integration. See [member custom_integrator].
  15. </description>
  16. <tutorials>
  17. </tutorials>
  18. <demos>
  19. </demos>
  20. <methods>
  21. <method name="_integrate_forces" qualifiers="virtual">
  22. <return type="void">
  23. </return>
  24. <argument index="0" name="state" type="Physics2DDirectBodyState">
  25. </argument>
  26. <description>
  27. Allows you to read and safely modify the simulation state for the object. Use this instead of [Node._physics_process] if you need to directly change the body's [code]position[/code] or other physics properties. By default it works in addition to the usual physics behavior, but [member custom_integrator] allows you to disable the default behavior and write custom force integration for a body.
  28. </description>
  29. </method>
  30. <method name="add_force">
  31. <return type="void">
  32. </return>
  33. <argument index="0" name="offset" type="Vector2">
  34. </argument>
  35. <argument index="1" name="force" type="Vector2">
  36. </argument>
  37. <description>
  38. Adds a positioned force to the body. Both the force and the offset from the body origin are in global coordinates.
  39. </description>
  40. </method>
  41. <method name="apply_impulse">
  42. <return type="void">
  43. </return>
  44. <argument index="0" name="offset" type="Vector2">
  45. </argument>
  46. <argument index="1" name="impulse" type="Vector2">
  47. </argument>
  48. <description>
  49. Applies a positioned impulse to the body (which will be affected by the body mass and shape). This is the equivalent of hitting a billiard ball with a cue: a force that is applied instantaneously. Both the impulse and the offset from the body origin are in global coordinates.
  50. </description>
  51. </method>
  52. <method name="get_angular_damp" qualifiers="const">
  53. <return type="float">
  54. </return>
  55. <description>
  56. Return the angular damp for this body.
  57. </description>
  58. </method>
  59. <method name="get_angular_velocity" qualifiers="const">
  60. <return type="float">
  61. </return>
  62. <description>
  63. Return the body angular velocity. This changes by physics granularity. See [method set_angular_velocity].
  64. </description>
  65. </method>
  66. <method name="get_applied_force" qualifiers="const">
  67. <return type="Vector2">
  68. </return>
  69. <description>
  70. Returns the body's total applied force.
  71. </description>
  72. </method>
  73. <method name="get_applied_torque" qualifiers="const">
  74. <return type="float">
  75. </return>
  76. <description>
  77. Returns the body's total applied torque.
  78. </description>
  79. </method>
  80. <method name="get_bounce" qualifiers="const">
  81. <return type="float">
  82. </return>
  83. <description>
  84. Return the body bounciness.
  85. </description>
  86. </method>
  87. <method name="get_colliding_bodies" qualifiers="const">
  88. <return type="Array">
  89. </return>
  90. <description>
  91. Returns a list of the bodies colliding with this one. Use [member contacts_reported] to set the maximum number reported. You must also set [member contact_monitor] to [code]true[/code].
  92. </description>
  93. </method>
  94. <method name="get_continuous_collision_detection_mode" qualifiers="const">
  95. <return type="int" enum="RigidBody2D.CCDMode">
  96. </return>
  97. <description>
  98. Return whether this body is using continuous collision detection.
  99. </description>
  100. </method>
  101. <method name="get_friction" qualifiers="const">
  102. <return type="float">
  103. </return>
  104. <description>
  105. Return the body friction.
  106. </description>
  107. </method>
  108. <method name="get_gravity_scale" qualifiers="const">
  109. <return type="float">
  110. </return>
  111. <description>
  112. Return the gravity factor.
  113. </description>
  114. </method>
  115. <method name="get_inertia" qualifiers="const">
  116. <return type="float">
  117. </return>
  118. <description>
  119. Returns the body's moment of inertia, which is computed automatically from the body's mass and assigned [Shape2D]s during the physics frame. Note that it will not yet have a value in the [code]_ready()[/code] function.
  120. </description>
  121. </method>
  122. <method name="get_linear_damp" qualifiers="const">
  123. <return type="float">
  124. </return>
  125. <description>
  126. Return the linear damp for this body.
  127. </description>
  128. </method>
  129. <method name="get_linear_velocity" qualifiers="const">
  130. <return type="Vector2">
  131. </return>
  132. <description>
  133. Returns the body's linear velocity. This changes when a physics frame has passed, not during a normal update. See [method set_linear_velocity].
  134. </description>
  135. </method>
  136. <method name="get_mass" qualifiers="const">
  137. <return type="float">
  138. </return>
  139. <description>
  140. Return the body mass.
  141. </description>
  142. </method>
  143. <method name="get_max_contacts_reported" qualifiers="const">
  144. <return type="int">
  145. </return>
  146. <description>
  147. Return the maximum contacts that can be reported. See [method set_max_contacts_reported].
  148. </description>
  149. </method>
  150. <method name="get_mode" qualifiers="const">
  151. <return type="int" enum="RigidBody2D.Mode">
  152. </return>
  153. <description>
  154. Return the current body mode, see [method set_mode].
  155. </description>
  156. </method>
  157. <method name="get_weight" qualifiers="const">
  158. <return type="float">
  159. </return>
  160. <description>
  161. Return the body weight given standard earth-weight (gravity 9.8).
  162. </description>
  163. </method>
  164. <method name="is_able_to_sleep" qualifiers="const">
  165. <return type="bool">
  166. </return>
  167. <description>
  168. Return true if the body has the ability to fall asleep when not moving. See [method set_can_sleep].
  169. </description>
  170. </method>
  171. <method name="is_contact_monitor_enabled" qualifiers="const">
  172. <return type="bool">
  173. </return>
  174. <description>
  175. Return whether contact monitoring is enabled.
  176. </description>
  177. </method>
  178. <method name="is_sleeping" qualifiers="const">
  179. <return type="bool">
  180. </return>
  181. <description>
  182. Return whether the body is sleeping.
  183. </description>
  184. </method>
  185. <method name="is_using_custom_integrator">
  186. <return type="bool">
  187. </return>
  188. <description>
  189. Return true if the body is not doing any built-in force integration.
  190. </description>
  191. </method>
  192. <method name="set_angular_damp">
  193. <return type="void">
  194. </return>
  195. <argument index="0" name="angular_damp" type="float">
  196. </argument>
  197. <description>
  198. Set the angular damp for this body. If this value is different from -1, any angular damp derived from the world or areas will be overridden.
  199. </description>
  200. </method>
  201. <method name="set_angular_velocity">
  202. <return type="void">
  203. </return>
  204. <argument index="0" name="angular_velocity" type="float">
  205. </argument>
  206. <description>
  207. Set the body angular velocity. Can be used sporadically, but [b]DON'T SET THIS IN EVERY FRAME[/b], because physics may be running in another thread and definitely runs at a different granularity. Use [method _integrate_forces] as your process loop if you want to have precise control of the body state.
  208. </description>
  209. </method>
  210. <method name="set_applied_force">
  211. <return type="void">
  212. </return>
  213. <argument index="0" name="force" type="Vector2">
  214. </argument>
  215. <description>
  216. Sets the applied force vector. This is the equivalent of firing a rocket: the force is applied constantly.
  217. </description>
  218. </method>
  219. <method name="set_applied_torque">
  220. <return type="void">
  221. </return>
  222. <argument index="0" name="torque" type="float">
  223. </argument>
  224. <description>
  225. Sets the applied torque.
  226. </description>
  227. </method>
  228. <method name="set_axis_velocity">
  229. <return type="void">
  230. </return>
  231. <argument index="0" name="axis_velocity" type="Vector2">
  232. </argument>
  233. <description>
  234. Sets the body's velocity on the given axis. The velocity in the given vector axis will be set as the given vector length. This is useful for jumping behavior.
  235. </description>
  236. </method>
  237. <method name="set_bounce">
  238. <return type="void">
  239. </return>
  240. <argument index="0" name="bounce" type="float">
  241. </argument>
  242. <description>
  243. Set the body bounciness, from 0 (no bounce) to 1 (full bounce).
  244. </description>
  245. </method>
  246. <method name="set_can_sleep">
  247. <return type="void">
  248. </return>
  249. <argument index="0" name="able_to_sleep" type="bool">
  250. </argument>
  251. <description>
  252. Set the body ability to fall asleep when not moving. This saves an enormous amount of processor time when there are plenty of rigid bodies (non static) in a scene.
  253. Sleeping bodies are not affected by forces until a collision or an [method apply_impulse] / [method set_applied_force] wakes them up. Until then, they behave like a static body.
  254. </description>
  255. </method>
  256. <method name="set_contact_monitor">
  257. <return type="void">
  258. </return>
  259. <argument index="0" name="enabled" type="bool">
  260. </argument>
  261. <description>
  262. Enable contact monitoring. This allows the body to emit signals when it collides with another.
  263. </description>
  264. </method>
  265. <method name="set_continuous_collision_detection_mode">
  266. <return type="void">
  267. </return>
  268. <argument index="0" name="mode" type="int" enum="RigidBody2D.CCDMode">
  269. </argument>
  270. <description>
  271. Set the continuous collision detection mode from the enum CCD_MODE_*.
  272. Continuous collision detection tries to predict where a moving body will collide, instead of moving it and correcting its movement if it collided. The first is more precise, and misses less impacts by small, fast-moving objects. The second is faster to compute, but can miss small, fast-moving objects.
  273. </description>
  274. </method>
  275. <method name="set_friction">
  276. <return type="void">
  277. </return>
  278. <argument index="0" name="friction" type="float">
  279. </argument>
  280. <description>
  281. Set the body friction, from 0 (frictionless) to 1 (full friction).
  282. </description>
  283. </method>
  284. <method name="set_gravity_scale">
  285. <return type="void">
  286. </return>
  287. <argument index="0" name="gravity_scale" type="float">
  288. </argument>
  289. <description>
  290. Set the gravity factor. This factor multiplies gravity intensity just for this body.
  291. </description>
  292. </method>
  293. <method name="set_inertia">
  294. <return type="void">
  295. </return>
  296. <argument index="0" name="inertia" type="float">
  297. </argument>
  298. <description>
  299. Set the body's moment of inertia. This is like mass, but for rotation: it determines how much torque it takes to rotate the body. The moment of inertia is usually computed automatically from the mass and the shapes, but this function allows you to set a custom value. Set 0 (or negative) inertia to return to automatically computing it.
  300. </description>
  301. </method>
  302. <method name="set_linear_damp">
  303. <return type="void">
  304. </return>
  305. <argument index="0" name="linear_damp" type="float">
  306. </argument>
  307. <description>
  308. Set the linear damp for this body. If this value is different from -1, any linear damp derived from the world or areas will be overridden.
  309. </description>
  310. </method>
  311. <method name="set_linear_velocity">
  312. <return type="void">
  313. </return>
  314. <argument index="0" name="linear_velocity" type="Vector2">
  315. </argument>
  316. <description>
  317. Set the body linear velocity. Can be used sporadically, but [b]DON'T SET THIS IN EVERY FRAME[/b], because physics may be running in another thread and definitely runs at a different granularity. Use [method _integrate_forces] as your process loop if you want to have precise control of the body state.
  318. </description>
  319. </method>
  320. <method name="set_mass">
  321. <return type="void">
  322. </return>
  323. <argument index="0" name="mass" type="float">
  324. </argument>
  325. <description>
  326. Set the body mass.
  327. </description>
  328. </method>
  329. <method name="set_max_contacts_reported">
  330. <return type="void">
  331. </return>
  332. <argument index="0" name="amount" type="int">
  333. </argument>
  334. <description>
  335. Set the maximum contacts to report. Bodies can keep a log of the contacts with other bodies, this is enabled by setting the maximum amount of contacts reported to a number greater than 0.
  336. </description>
  337. </method>
  338. <method name="set_mode">
  339. <return type="void">
  340. </return>
  341. <argument index="0" name="mode" type="int" enum="RigidBody2D.Mode">
  342. </argument>
  343. <description>
  344. Set the body mode, from the MODE_* enum. This allows to change to a static body or a character body.
  345. </description>
  346. </method>
  347. <method name="set_sleeping">
  348. <return type="void">
  349. </return>
  350. <argument index="0" name="sleeping" type="bool">
  351. </argument>
  352. <description>
  353. Set whether a body is sleeping or not. Sleeping bodies are not affected by forces until a collision or an [method apply_impulse] / [method set_applied_force] wakes them up. Until then, they behave like a static body.
  354. </description>
  355. </method>
  356. <method name="set_use_custom_integrator">
  357. <return type="void">
  358. </return>
  359. <argument index="0" name="enable" type="bool">
  360. </argument>
  361. <description>
  362. Pass true to disable the internal force integration (like gravity or air friction) for this body. Other than collision response, the body will only move as determined by the [method _integrate_forces] function, if defined.
  363. </description>
  364. </method>
  365. <method name="set_weight">
  366. <return type="void">
  367. </return>
  368. <argument index="0" name="weight" type="float">
  369. </argument>
  370. <description>
  371. Set the body weight given standard earth-weight (gravity 9.8). Not really useful for 2D since most measures for this node are in pixels.
  372. </description>
  373. </method>
  374. <method name="test_motion">
  375. <return type="bool">
  376. </return>
  377. <argument index="0" name="motion" type="Vector2">
  378. </argument>
  379. <argument index="1" name="margin" type="float" default="0.08">
  380. </argument>
  381. <argument index="2" name="result" type="Physics2DTestMotionResult" default="null">
  382. </argument>
  383. <description>
  384. Returns [code]true[/code] if a collision would result from moving in the given vector. [code]margin[/code] increases the size of the shapes involved in the collision detection, and [code]result[/code] is an object of type [Physics2DTestMotionResult], which contains additional information about the collision (should there be one).
  385. </description>
  386. </method>
  387. </methods>
  388. <members>
  389. <member name="angular_damp" type="float" setter="set_angular_damp" getter="get_angular_damp">
  390. Damps the body's [member angular_velocity]. If [code]-1[/code] the body will use the "Default Angular Damp" in "Project &gt; Project Settings &gt; Physics &gt; 2d". Default value: [code]-1[/code].
  391. </member>
  392. <member name="angular_velocity" type="float" setter="set_angular_velocity" getter="get_angular_velocity">
  393. The body's rotational velocity.
  394. </member>
  395. <member name="bounce" type="float" setter="set_bounce" getter="get_bounce">
  396. The body's bounciness. Default value: [code]0[/code].
  397. </member>
  398. <member name="can_sleep" type="bool" setter="set_can_sleep" getter="is_able_to_sleep">
  399. If [code]true[/code] the body will not calculate forces and will act as a static body if there is no movement. The body will wake up when other forces are applied via collisions or by using [method apply_impulse] or [method add_force]. Default value: [code]true[/code].
  400. </member>
  401. <member name="contact_monitor" type="bool" setter="set_contact_monitor" getter="is_contact_monitor_enabled">
  402. If [code]true[/code] the body will emit signals when it collides with another RigidBody2D. See also [member contacts_reported]. Default value: [code]false[/code].
  403. </member>
  404. <member name="contacts_reported" type="int" setter="set_max_contacts_reported" getter="get_max_contacts_reported">
  405. The maximum number of contacts to report. Default value: [code]0[/code].
  406. </member>
  407. <member name="continuous_cd" type="int" setter="set_continuous_collision_detection_mode" getter="get_continuous_collision_detection_mode" enum="RigidBody2D.CCDMode">
  408. Continuous collision detection mode. Default value: [code]CCD_MODE_DISABLED[/code].
  409. Continuous collision detection tries to predict where a moving body will collide instead of moving it and correcting its movement after collision. Continuous collision detection is slower, but more precise and misses fewer collisions with small, fast-moving objects. Raycasting and shapecasting methods are available. See [code]CCD_MODE_[/code] constants for details.
  410. </member>
  411. <member name="custom_integrator" type="bool" setter="set_use_custom_integrator" getter="is_using_custom_integrator">
  412. If [code]true[/code] internal force integration is disabled for this body. Aside from collision response, the body will only move as determined by the [method _integrate_forces] function.
  413. </member>
  414. <member name="friction" type="float" setter="set_friction" getter="get_friction">
  415. The body's friction. Values range from [code]0[/code] (frictionless) to [code]1[/code] (maximum friction). Default value: [code]1[/code].
  416. </member>
  417. <member name="gravity_scale" type="float" setter="set_gravity_scale" getter="get_gravity_scale">
  418. Multiplies the gravity applied to the body. The body's gravity is calculated from the "Default Gravity" value in "Project &gt; Project Settings &gt; Physics &gt; 2d" and/or any additional gravity vector applied by [Area2D]s. Default value: [code]1[/code].
  419. </member>
  420. <member name="linear_damp" type="float" setter="set_linear_damp" getter="get_linear_damp">
  421. Damps the body's [member linear_velocity]. If [code]-1[/code] the body will use the "Default Linear Damp" in "Project &gt; Project Settings &gt; Physics &gt; 2d". Default value: [code]-1[/code].
  422. </member>
  423. <member name="linear_velocity" type="Vector2" setter="set_linear_velocity" getter="get_linear_velocity">
  424. The body's linear velocity.
  425. </member>
  426. <member name="mass" type="float" setter="set_mass" getter="get_mass">
  427. The body's mass. Default value: [code]1[/code].
  428. </member>
  429. <member name="mode" type="int" setter="set_mode" getter="get_mode" enum="RigidBody2D.Mode">
  430. The body's mode. See [code]MODE_*[/code] constants. Default value: [code]MODE_RIGID[/code].
  431. </member>
  432. <member name="sleeping" type="bool" setter="set_sleeping" getter="is_sleeping">
  433. If [code]true[/code] the body is sleeping and will not calculate forces until woken up by a collision or by using [method apply_impulse] or [method add_force].
  434. </member>
  435. <member name="weight" type="float" setter="set_weight" getter="get_weight">
  436. The body's weight based on its mass and the "Default Gravity" value in "Project &gt; Project Settings &gt; Physics &gt; 2d".
  437. </member>
  438. </members>
  439. <signals>
  440. <signal name="body_entered">
  441. <argument index="0" name="body" type="Object">
  442. </argument>
  443. <description>
  444. Emitted when a body enters into contact with this one. [member contact_monitor] must be [code]true[/code] and [member contacts_reported] greater than [code]0[/code].
  445. </description>
  446. </signal>
  447. <signal name="body_exited">
  448. <argument index="0" name="body" type="Object">
  449. </argument>
  450. <description>
  451. Emitted when a body exits contact with this one. [member contact_monitor] must be [code]true[/code] and [member contacts_reported] greater than [code]0[/code].
  452. </description>
  453. </signal>
  454. <signal name="body_shape_entered">
  455. <argument index="0" name="body_id" type="int">
  456. </argument>
  457. <argument index="1" name="body" type="Object">
  458. </argument>
  459. <argument index="2" name="body_shape" type="int">
  460. </argument>
  461. <argument index="3" name="local_shape" type="int">
  462. </argument>
  463. <description>
  464. Emitted when a body enters into contact with this one. Reports colliding shape information. See [CollisionObject2D] for shape index information. [member contact_monitor] must be [code]true[/code] and [member contacts_reported] greater than [code]0[/code].
  465. </description>
  466. </signal>
  467. <signal name="body_shape_exited">
  468. <argument index="0" name="body_id" type="int">
  469. </argument>
  470. <argument index="1" name="body" type="Object">
  471. </argument>
  472. <argument index="2" name="body_shape" type="int">
  473. </argument>
  474. <argument index="3" name="local_shape" type="int">
  475. </argument>
  476. <description>
  477. Emitted when a body shape exits contact with this one. Reports colliding shape information. See [CollisionObject2D] for shape index information. [member contact_monitor] must be [code]true[/code] and [member contacts_reported] greater than [code]0[/code].
  478. </description>
  479. </signal>
  480. <signal name="sleeping_state_changed">
  481. <description>
  482. Emitted when [member sleeping] changes.
  483. </description>
  484. </signal>
  485. </signals>
  486. <constants>
  487. <constant name="MODE_RIGID" value="0">
  488. Rigid mode. The body behaves as a physical object. It collides with other bodies and responds to forces applied to it. This is the default mode.
  489. </constant>
  490. <constant name="MODE_STATIC" value="1">
  491. Static mode. The body behaves like a [StaticBody2D] and does not move.
  492. </constant>
  493. <constant name="MODE_CHARACTER" value="2">
  494. Character mode. Similar to [code]MODE_RIGID[/code], but the body can not rotate.
  495. </constant>
  496. <constant name="MODE_KINEMATIC" value="3">
  497. Kinematic mode. The body behaves like a [KinematicBody2D], and must be moved by code.
  498. </constant>
  499. <constant name="CCD_MODE_DISABLED" value="0">
  500. Continuous collision detection disabled. This is the fastest way to detect body collisions, but can miss small, fast-moving objects.
  501. </constant>
  502. <constant name="CCD_MODE_CAST_RAY" value="1">
  503. Continuous collision detection enabled using raycasting. This is faster than shapecasting but less precise.
  504. </constant>
  505. <constant name="CCD_MODE_CAST_SHAPE" value="2">
  506. Continuous collision detection enabled using shapecasting. This is the slowest CCD method and the most precise.
  507. </constant>
  508. </constants>
  509. </class>