Jump to content

Give Sprites Planet-like Gravity Qualities


lobsterhands
 Share

Recommended Posts

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

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 :P

 

I'll be interested to see such experiment. 

Link to comment
Share on other sites

@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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...