update.lua 1.7 KB

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