gamelab / kiwi.js

Kiwi.js is a blazingly fast mobile & desktop browser based HTML5 game framework. It uses CocoonJS for publishing to the AppStore.
www.kiwijs.org
MIT License
1.41k stars 195 forks source link

Add gravity to the ArcadePhysics component. #182

Open zfreiberg opened 9 years ago

zfreiberg commented 9 years ago

Ideally this property would be a point ( or vector2 but I think we use points ) which would allow for gravity on all axis.

example of use:

this.spaceship.physics.gravity.x = 10;

elliothimmelfarb commented 8 years ago

This should be pretty easy, right?

BenjaminDRichards commented 8 years ago

Hmm. It's worth discussing, certainly.

On the plus side, a gravity property would be compatible with other sources of acceleration in a simulation.

On the minus side, under most circumstances it would simply be a second acceleration term, adding to the computational cost of the component. Gravity is an acceleration, after all; and there aren't many use cases for ArcadePhysics where you need to accelerate something in a non-gravitational context. Perhaps a situation where you're launching rockets in a gravity well with realistic acceleration? Under most use cases, you'd simply give an object an initial velocity and put gravity into the extant acceleration property.

The purpose of ArcadePhysics is to provide a simple, low-cost physics simulation. The Chipmunk Physics plugin provides more in-depth simulations. There are certainly cases for a middle ground simulation which isn't as heavy as Chipmunk, but offers more options than Arcade; but this might be better implemented on a per-game basis.

Anybody else have thoughts on the matter?