Skip to content

Instantly share code, notes, and snippets.

View ste2425's full-sized avatar

Stephen Cooper ste2425

View GitHub Profile
@ShimShamSam
ShimShamSam / stopSidewaysVelocity.js
Last active April 24, 2024 03:08
Phaser Physics - Stop sideways velocity
/**
* Negate sideways velocity on an object being acted upon by a Phaser physics engine.
* The primary use for this is to simulate vehicle movement by negating "drift" when the vehicle turns.
* @param {Phaser.Sprite} sprite The sprite whose sideways velocity you want to negate
*/
function stopSidewaysVelocity(sprite) {
// Recycle the same object to conserve memory
if(!stopSidewaysVelocity.sideways) {
stopSidewaysVelocity.sideways = {};
}