Skip to content

Instantly share code, notes, and snippets.

@jfraboni
Created February 10, 2019 12:00
Show Gist options
  • Save jfraboni/a9e3cd04402754919b6a20f6e5c8cc8d to your computer and use it in GitHub Desktop.
Save jfraboni/a9e3cd04402754919b6a20f6e5c8cc8d to your computer and use it in GitHub Desktop.
Snippet: Update a body's position and rotation
/**
* Updates the x and y properties of a body based on its
* velocityX and velocityY, and, updates the rotation of
* a body based on its rotationalVelocity.
*
* @param {Object} body: The body must be an Object
* with x, y, rotation, velocityX, velocityY, and
* rotationalVelocity properties.
*/
updatePosition(body) {
body.x += body.velocityX;
body.y += body.velocityY;
body.rotation += body.rotationalVelocity;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment