I have a script here that I found in a tutorial for making spherical gravity setups a la Super Mario Galaxy. My setup is that this script is in a Python Logic Brick attached to a Collision sensor that detects if the player or other objects are in the radius of a sphere, causing the objects with a certain property
gravity to drop to the center of the spherical area.
I don’t attach this logic to the planetoid itself but rather to static ghosted 3D models that envelop it like a gravitational field so I can use them similarly to a near sensor but with a little more control over where things are detected since I can actually model the area where gravity will work.
So what I need now is to rework this script for other shapes and types (such as local linear gravity and cylindrical-shaped gravity) also controlled by this same method, but I can’t figure out how to do it by myself.
For local linear gravity basically I need it such that the gravity field pulling on the object pulls it linearly along the field’s local Z axis. For cylindrical gravity it needs to work like the spherical one but only on 2 axes (the field’s local X and Y) instead of all 3.
Thanks for any help!
Spherical Gravity Script:
from bge import logic from mathutils import Vector cont = logic.getCurrentController() own = cont.owner scene = logic.getCurrentScene() for obj in scene.objects: if "gravity" in obj: pull = Vector(obj.getVectTo(own)) pull.magnitude = own["gAmount"] obj.applyForce(pull) player = scene.objects["Player"] align = own.getVectTo("Player") player.alignAxisToVect(align,2,0.5)