schmevie15 Posted December 11, 2014 Share Posted December 11, 2014 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! Link to comment Share on other sites More sharing options...
trueicecold Posted December 13, 2014 Share Posted December 13, 2014 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? Link to comment Share on other sites More sharing options...
jpdev Posted December 14, 2014 Share Posted December 14, 2014 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.) Link to comment Share on other sites More sharing options...
valueerror Posted December 15, 2014 Share Posted December 15, 2014 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/ lighterletter 1 Link to comment Share on other sites More sharing options...
schmevie15 Posted December 15, 2014 Author Share Posted December 15, 2014 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!! Link to comment Share on other sites More sharing options...
valueerror Posted December 16, 2014 Share Posted December 16, 2014 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 Link to comment Share on other sites More sharing options...
schmevie15 Posted December 16, 2014 Author Share Posted December 16, 2014 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! Link to comment Share on other sites More sharing options...
valueerror Posted December 16, 2014 Share Posted December 16, 2014 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 Link to comment Share on other sites More sharing options...
schmevie15 Posted December 16, 2014 Author Share Posted December 16, 2014 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!! Link to comment Share on other sites More sharing options...
valueerror Posted December 16, 2014 Share Posted December 16, 2014 well thats easy... don't zero the rotation on every frame.. the ball can not rotate and roll if you definitely forbid it Link to comment Share on other sites More sharing options...
valueerror Posted December 16, 2014 Share Posted December 16, 2014 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; Link to comment Share on other sites More sharing options...
schmevie15 Posted December 16, 2014 Author Share Posted December 16, 2014 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!!! Link to comment Share on other sites More sharing options...
valueerror Posted December 17, 2014 Share Posted December 17, 2014 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) Link to comment Share on other sites More sharing options...
Recommended Posts