Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3481430
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:26:51+00:00 2026-05-18T10:26:51+00:00

Currently I am using the Box2D physics engine in a game of mine –

  • 0

Currently I am using the Box2D physics engine in a game of mine – and I was wondering if I could create a gravity well of sorts, in which all the bodies are attracted to a single arbitrary point. Is there a certain way to do this, or will i have to apply a custom force of sorts to each body? (I tried making a static superdense body, but Box2D doesn’t apply Newton’s Law of Universal Gravitation on a body-to-body basis)

Also, is there a way to make an anti-gravity well? Could I make a denser sphere centered around an arbitrary point and use buoyancy to achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:26:52+00:00Added an answer on May 18, 2026 at 10:26 am

    This functionality isn’t built into Box2D unfortunately. The easiest thing to do is get the angle and the distance between the gravity well and the rigid body and set the bodies velocity accordingly.

    To get the angle:

    double dx = rigidBodyX - gravityWellX;
    double dy = rigidBodyY - gravityWellY;
    double angle = atan2(dy, dx);
    // angle is in radians, use atan2(dy, dx) / PI * 180 if 
    // you need degrees
    

    To get the distance:

    double dx = rigidBodyX - gravityWellX;
    double dy = rigidBodyY - gravityWellY;
    double dist = sqrt(dx * dx + dy * dy);
    

    I whipped up a quick example using flash and a library I wrote called QuickBox2D. It might not be that helpful since the syntax is very different from the C++ Box2D library, but the basic principal is the same. It’s also not a perfect example, but it might get you started.

    See The Flash Example

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Salut, I'm currently working on a pool game in flash, using box2d for physics
I'm using a composite design in my current game which works pretty well. All
I am currently making a game for the iPad and iPhone using cocos2d, Box2D
I am making a game using Andengine/Box2D physics addon. I experienced the random crashes
Using AndEngine Physics Box2D i am trying to drag a body from side to
I'm developing 2D Side scroll Android Game, using AndEngine and its BOX2D extension. I
As a quick overview: I'm trying to make a game of pool using Box2D
Hello stackoverflow community, I'm working on a puzzle game using Cocos2D/Box2D were the player
I am new to Objective-C. I am currently working on a game using Cocos2D
I'm making a basic platformer engine in AS3, and I'm currently implementing gravity. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.