newWorld.lua 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. return {
  2. tag = 'world',
  3. summary = 'Create a new World.',
  4. description = [[
  5. Creates a new physics World, which tracks the overall physics simulation, holds collider
  6. objects, and resolves collisions between them.
  7. ]],
  8. arguments = {
  9. xg = {
  10. type = 'number',
  11. default = '0',
  12. description = 'The x component of the gravity force.'
  13. },
  14. yg = {
  15. type = 'number',
  16. default = '-9.81',
  17. description = 'The y component of the gravity force.'
  18. },
  19. zg = {
  20. type = 'number',
  21. default = '0',
  22. description = 'The z component of the gravity force.'
  23. },
  24. allowSleep = {
  25. type = 'boolean',
  26. default = 'true',
  27. description = 'Whether or not colliders will automatically be put to sleep.'
  28. },
  29. tags = {
  30. type = 'table',
  31. default = '{}',
  32. description = 'A list of collision tags colliders can be assigned to.'
  33. }
  34. },
  35. returns = {
  36. world = {
  37. type = 'World',
  38. description = 'A whole new World.'
  39. }
  40. },
  41. variants = {
  42. {
  43. arguments = { 'xg', 'yg', 'zg', 'allowSleep', 'tags' },
  44. returns = { 'world' }
  45. }
  46. },
  47. notes = [[
  48. A World must be updated with `World:update` in `lovr.update` for the physics simulation to
  49. advance.
  50. ]],
  51. example = {
  52. description = [[
  53. Create a new world, add a collider to it, and update it, printing out its position as it
  54. falls.
  55. ]],
  56. code = [[
  57. function lovr.load()
  58. world = lovr.physics.newWorld()
  59. box = world:newBoxCollider()
  60. end
  61. function lovr.update(dt)
  62. world:update(dt)
  63. print(box:getPosition())
  64. end
  65. ]]
  66. }
  67. }