grapefruitjs / grapefruit

Outdated, I recommend you use photonstorm/phaser instead!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Default Gravity

nkijak opened this issue · comments

src/physics/PhysicsSystem.js:5

The docs state you should pass a number for gravity or it will default to 9.87. But ensureVector will turn that into [num,num] instead of what I would assume should be [0,num]. This can be overcome by passing that array for gravity in the settings. Not sure if this is intentional though.

Past that, I could not figure out what lines 155,156 are for. With those included my sprite simply stayed in place. I commented out the lines that add those two constraints to the space and my sprite began to fall as expected.

This is for a side scroller/platform game where gravity is in the positive y direction. Again, not sure if this is intended or I'm doing it wrong.

Good catch about the ensureVector call! The lines 155-156 are for controlling bodies. If you set the velocity of a physical body directly unexpected things happen (such as it not colliding). However, in chipmunk the way to correctly control a body is to create a "control body" and attach the two via a gear and pivot joint.

There is likely an issue with applying gravity to the control body, I'll try to look into it.

I'm not setting velocity yet (I assume you mean if I was attempting to move the sprite) but I am having trouble setting a "ground" tile and having my sprite collide. I guess that's what you mean. If you do look into it, it seems to be the pivot joint that's canceling out any movement. As long as that's included, gravity has no effect.

That is interesting, I will definitely look into it.

So I saw this in action, and removing the control body did fix the issue (but caused other ones). Grapefruit is going through a major reorg and lots of components (including physics) are being rewritten. When it is done (one more week?) the physics will be much simplier and "arcade" like. I can come back and integrate Chipmunk or Box2D later.

Morale of the post is: Hang in there, new things are coming that should fix you right up.

This has been fixed in the modular branch.