Vacuum Stimulated Gravity In The BGE

Vacuum Stimulated Gravity In The BGE

This resource allows real life gravity to work in your games, so that an object can attract towards another rather than always moving in one direction. Enjoy!

BGE 2.78 or higher required!

real world gravity in the bge.

1 Like

I hope someone out there still has this file because it’s been lost to time now and I did work decently hard on it. it was designed to make real world gravity in the game engine, and did so with an extremel level of precision and accuracy accounting for as many variables as possible.

Don’t have the file.
But it is an inspiring topic!
Getting motivation to create something in UPBGE 0.3.

goodluck. it’s such a pity this vanished. it actually accounted for every little variable on the gravity formula.

1 Like

Thanks!!
Searched the UPBGE discord channel for your file but nothing came up.
I really got inspired by your topic.

1 Like

i’m glad to hear that but mine was for the bge not upbge. in any case I wish you luck!

Thank you!!!

The main math won’t be different in bge I think.
Here’s a fast simplified blend for 2.79 you can improve to your liking:
279_Gravity_All.blend (701.4 KB)

import bge

cont = bge.logic.getCurrentController()
own = cont.owner
scene = bge.logic.getCurrentScene()

if 'init_status' not in own:
    own['init_status']=True 
    own['Planet_List']=[obj for obj in scene.objects if 'planet' in obj]
    
########### apply gravity forces to everything               
for obj in own['Planet_List']:
    for Target in own['Planet_List']:
        distance, globalVector, localVector = Target.getVectTo(obj)
        
        if distance>0:
            Target.applyForce(globalVector/(distance*distance)*own['gravity']*obj.mass*Target.mass,False)
1 Like

haha this is neat. I like it. but If you want something closer to what I had, you’ll need something slightly more complex.

import numpy as np

def einstein_tensor(mass1, volume1, mass2, volume2, distance):
    G = 6.67430e-11  # Gravitational constant (m^3 kg^-1 s^-2)
    c = 3e8  # Speed of light (m/s)
    pi = np.pi

    T00 = mass1 + mass2
    T11 = volume1 + volume2

    g = np.array([
        [1, 0, 0, 0],
        [0, -1, 0, 0],
        [0, 0, -1, 0],
        [0, 0, 0, -1]
    ])

    R = np.zeros((4, 4))
    R[0, 0] = T00 / distance**2
    R[1, 1] = T11 / distance**2

    R_scalar = np.trace(R)

    G_tensor = R - 0.5 * R_scalar * g

    Lambda = 0
    T = np.zeros((4, 4))
    T[0, 0] = T00
    T[1, 1] = T11

    einstein_eq = G_tensor + Lambda * g - (8 * pi * G / c**4) * T

    return einstein_eq

def calculate_relative_velocity(einstein_eq, distance):
    G = 6.67430e-11  # Gravitational constant (m^3 kg^-1 s^-2)
    c = 3e8  # Speed of light (m/s)
    
    # Simplified calculation of gravitational potential (Phi)
    Phi = -G * einstein_eq[0, 0] / distance

    # Using gravitational potential to estimate relative velocity
    v_rel = np.sqrt(2 * abs(Phi))

    return v_rel

# Example usage
mass1 = 5.97e24  # Mass of object 1 (in kg)
volume1 = 1.08e21  # Volume of object 1 (in m^3)
mass2 = 7.34e22  # Mass of object 2 (in kg)
volume2 = 2.19e10  # Volume of object 2 (in m^3)
distance = 3.84e8  # Distance between the objects (in meters)

einstein_result = einstein_tensor(mass1, volume1, mass2, volume2, distance)
v_rel = calculate_relative_velocity(einstein_result, distance)

print("Einstein Tensor Result:")
print(einstein_result)

print("Relative Velocity (m/s):")
print(v_rel)