# Rolling a circle down a hill?

## Recommended Posts

So currently I am making a 2D game with Phaser P2 Physics that involves a ball rolling along, sort of like a platformer, I am trying to make it both difficult for the ball to roll up a hill and then easy for it to roll down. I know increasing the gravity will do the trick, but then the global gravity will be increased and the ball will basically be sucked to the ground. I've performed some tests and I had to change the gravity to about 10000 to get it to roll down at a noticeable speed. Now is there an easier/better way to do this using some of the Phaser P2 Physics attributes? I appreciate any and all help!

Thanks!

##### Share on other sites

I'm not familiar with p2, but physics speaking, wouldn't giving the ball constant force/torque achieve this? Why do you need to play with gravity for this?

##### Share on other sites

Your friction might just be too high.

(Create contact materials for the ball and the ground, and define a low friction value - then the ball should roll down hills easier.)

##### Share on other sites

if you give the ball a constant force this force will always work against you.. what if the ball should roll down on the other side of the hill??  constant force would make it roll UP the hill then..  why gravity ?  because it is  a physics simulation .. gravity is all you need!

look here for inspiration.. i just made a small example for you without materials..  (materials are still a good idea to make it feel more real give it a little bit of friction)

http://test.xapient.net/phaser/ballhillrolldown/

##### Share on other sites

Hey thanks for the replies guys! I figured gravity was the answer. @valueerror, where are you setting the gravity? I see that you set the global gravity to be 1400, but you don't seem to change it after that. Are you giving the ball gravity or increasing the global gravity anywhere? Thanks for the help!!

##### Share on other sites

nope..   1400 is almost "real" gravity  (9.81g or so) -  this is my setting for the whole game and for all objects..  i don't change anything gravity related later..  wasn't necessary yet

##### Share on other sites

I still don't get how you're able to get your ball to roll like that! My gravity is about the same my global friction is around 2 and the ball takes an extremely long time to roll down the hill. Thanks again!

##### Share on other sites

i would have to see your game to tell you more about it..

meanwhile.. here is my demo as zip file so you can play around with it

ballhillrolldown.zip

##### Share on other sites

Awesome thanks! Here is a public link:https://dl.dropboxusercontent.com/u/15582110/circle_game/Meteroar.html basically I want the pink ball to be able to roll on the pyramid mountain thing and other sloping objects. Thanks again!!

##### Share on other sites

well thats easy...  don't zero the rotation on every frame..  the ball can not rotate and roll if you definitely forbid it

##### Share on other sites

btw.  why these enormous values for body.mass ????

if you don't want a body to move set it to static:

`pyramid.body.static = true;`

to get your player to stop you could play with the values for

` sally.body.angularDamping=0.9;`
##### Share on other sites

Hey thanks a lot! I have a question though, it rolls fine now, but if I try to rotate while rolling down the hill it reverts to the speed of the rotation, the rotating doesn't contribute to the speed it's going at already. Also thanks for the pyramid advice I was looking for something like that I remember in ARCADE physics it was something like immovable! Thanks!!!

##### Share on other sites

hmm..  you probably should try to work with angularForce instead of velocity..  it would allow to speed up the rotation further...  (but then you would have to limit it otherwise it would get too fast at some point)

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.