Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (527)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (594)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Game Mechanics / Re: Gravity hole: Objects moving near a hole, shifts its projection towards the hole on: 2012-08-06 21:57:00
Sounds like you're wanting to simulate something like a gravity well, where an object is caught in the gravity field of a larger more massive object and is pulled inwards. Jonjava above does a good job of explaining the physics involved, i'd like to try and take it a tiny bit further.

Once you calculate the force due to gravity on the smaller object, F, i think its useful to use this to calculate the acceleration on the object, since F = mass x acceleration, and work with acceleration instead of F alone. This way you can just use the acceleration value to update the velocity, then use the new velocity value to update the x and y position co-ordinates of the object.

If you call m1 the mass of the larger more massive object, and m2 as the mass of the smaller orbiting object, then the acceleration of m2 is found by the following...



If m1 is much larger than m2, then the above shows that you can effectively drop the value of m2 from the calculation of acceleration due to gravity on m2.

Once you have the acceleration, you find it's horizontal and vertical components. You've already nailed that in your code above using trig and the angle.

In each frame just keep adding the horizontal and vertical components of the acceleration to the horizontal and vertical components of the object's velocity, and in turn add these velocity components to the x and y position co-ordinates of the object to simulate the effect of gravity, though rather roughly. A more accurate simulation would include higher order integration factors to accommodate the effects of a variable acceleration rate.

If you're having bother splitting a vector into its horizontal and vertical components, check out the applet I knocked up to help visualise this at the link below. Click the mouse left button and drag it around the screen to see a vector and its horizontal and vertical components.

http://www.bahill.net/myApplet.html

Hope all that makes sense and is of some help to you,

cheers,

Bahill
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

PocketCrafter7 (12 views)
2014-11-28 16:25:35

PocketCrafter7 (8 views)
2014-11-28 16:25:09

PocketCrafter7 (9 views)
2014-11-28 16:24:29

toopeicgaming1999 (76 views)
2014-11-26 15:22:04

toopeicgaming1999 (66 views)
2014-11-26 15:20:36

toopeicgaming1999 (15 views)
2014-11-26 15:20:08

SHC (29 views)
2014-11-25 12:00:59

SHC (27 views)
2014-11-25 11:53:45

Norakomi (32 views)
2014-11-25 11:26:43

Gibbo3771 (28 views)
2014-11-24 19:59:16
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!