update.lua 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. return {
  2. tag = 'worldBasics',
  3. summary = 'Update the World.',
  4. description = [[
  5. Updates the World, advancing the physics simulation forward in time and resolving collisions
  6. between colliders in the World.
  7. ]],
  8. arguments = {
  9. dt = {
  10. type = 'number',
  11. description = 'The amount of time to advance the simulation forward.'
  12. },
  13. resolver = {
  14. type = 'function',
  15. arguments = {
  16. {
  17. name = 'world',
  18. type = 'World'
  19. }
  20. },
  21. returns = {},
  22. variants = {
  23. {
  24. arguments = { 'dt', 'resolver' },
  25. returns = {}
  26. }
  27. },
  28. default = 'nil',
  29. description = [[
  30. The collision resolver function to use. This will be called before updating to allow for
  31. custom collision processing. If absent, a default will be used.
  32. ]]
  33. }
  34. },
  35. returns = {},
  36. variants = {
  37. {
  38. arguments = { 'dt', 'resolver' },
  39. returns = {}
  40. }
  41. },
  42. notes = [[
  43. It is common to pass the `dt` variable from `lovr.update` into this function.
  44. The default collision resolver function is:
  45. function defaultResolver(world)
  46. world:computeOverlaps()
  47. for shapeA, shapeB in world:overlaps() do
  48. world:collide(shapeA, shapeB)
  49. end
  50. end
  51. Additional logic could be introduced to the collision resolver function to add custom collision
  52. behavior or to change the collision parameters (like friction and restitution) on a
  53. per-collision basis.
  54. > If possible, use a fixed timestep value for updating the World. It will greatly improve the
  55. > accuracy of the simulation and reduce bugs. For more information on implementing a fixed
  56. > timestep loop, see [this article](http://gafferongames.com/game-physics/fix-your-timestep/).
  57. ]],
  58. related = {
  59. 'World:computeOverlaps',
  60. 'World:overlaps',
  61. 'World:collide'
  62. }
  63. }