lobsterhands Posted May 24, 2014 Share Posted May 24, 2014 I'm working on prototyping a game that will allow a player to walk all the way around a sprite (think of it as a planet, despite it being a rectangle). Please view the very simple idea here: http://lyledenman.com/phaser/gravity/ Instead of the player falling off the side of the "planet" and landing on the ground below, I want him to be able to walk all the way around the rectangle. Is this possible using Arcade physics? Basically, I want to set the rectangle sprite to have its own gravity. Also, I'd like to eventually add another "planet" which has its own gravity. Any ideas? Would I have to use a circle instead? Link to comment Share on other sites More sharing options...
Mike Posted May 24, 2014 Share Posted May 24, 2014 It's not a Phaser specific, it's not even JS but its a good source of info about the topic: http://www.emanueleferonato.com/2012/03/28/simulate-radial-gravity-also-know-as-planet-gravity-with-box2d-as-seen-on-angry-birds-space/ About the rectangle form it should be a problem it can even simplify the gravity to 4 directions depending on which side of the "planet" are you the gravity changes I'll be interested to see such experiment. lobsterhands 1 Link to comment Share on other sites More sharing options...
valueerror Posted May 24, 2014 Share Posted May 24, 2014 isnt it possible to apply a force into the direction of a specific point? that point would be in the middle of the planet sprite. and we would not need gravity at all lobsterhands 1 Link to comment Share on other sites More sharing options...
lobsterhands Posted May 24, 2014 Author Share Posted May 24, 2014 @mike & @valueerror, Thank you for the responses and ideas. I've been playing with this a bit and I have this so far: http://lyledenman.com/phaser/gravity/ *You can currently JUMP using the UP or Spacebar key if you are on the top/bottom of the planet. I really want to keep the rectangle, though I can see it causing some issues with gravity on the X axis. I would like for the Y gravity to turn off completely while the player is on the side of the rectangle, but that is just a matter of tweaking my code a bit. Link to comment Share on other sites More sharing options...
PixelPicoSean Posted May 24, 2014 Share Posted May 24, 2014 Here's an article about planet gravity: https://www.scirra.com/tutorials/273/how-to-make-a-gravity-based-platformer?page=4 It's a simple guide to achieve this goal with Construct 2, but should still be helpful. The core is to create extra "Gravzone", both rounded or rect shape. While player is overlapping a zone, it gives the player a specific acceleration. Following that idea you can create a rect zone on each side of your terrain, add them into a zone group and check for overlapping on update method. Link to comment Share on other sites More sharing options...
lobsterhands Posted May 26, 2014 Author Share Posted May 26, 2014 Should I be doing this project with Arcade physics? Or would P2 make more sense? Link to comment Share on other sites More sharing options...
Recommended Posts