Classes | |
class | GravSettings |
Public Types | |
enum | GravityMode { Constant, Realistic, Linear, ManualRate } |
Public Member Functions | |
bool | AddWorld (World w) |
bool | AddWorldObject (WorldObject o) |
bool | RemoveWorld (World w) |
bool | RemoveWorldObject (WorldObject o) |
void | SetGravityScalar (float scalar) |
float | GetGravityScalar () |
void | SetGravityMode (GravityMode mode) |
GravityMode | GetGravityMode () |
void | SetGravityDecay (float decay) |
float | GetGravityDecay () |
bool | GetGravityActive () |
void | SetGravityActive (bool b) |
Public Attributes | |
bool | gravityActive = true |
GravSettings | gravitySettings |
List< World > | worlds |
List< WorldObject > | worldObjects |
The WorldPhysicsSystem class manages and applies sphere based gravity
This manages a list of Worlds and WorldObjects. During FixedUpdate(), each world imposes gravity on each WorldObject. WorldObjects may be Worlds and vice versa.
To add an object, use AddWorld(...) or AddWorldObject(...). To remove, use the paired methods RemoveWorld(...) and RemoveWorldObject(...).
Using the gravity scalar feature is crucial for properly balancing your gravity system. For example, if Planet A has twice as much gravity as Planet B, then set Planet A's gravity strength to 2 and Planet B's gravity strength to 1. Then set gravityScalar t a basic unit size. In this case, we'll use 1000. This will set Planet A's gravity to 2000, while keeping Planet B's gravity to 1000.
This is an m*n performance system, with moderately expensive calculations. Where 'm' is the number of Worlds and 'n' is the number of WorldObjects.The code will run m*n calculations per FixedUpdate. To minimize the impact of the calculations, try using the Constant gravity mode as it has a smaller cpu load per calculation.
This enumeration defines various gravity modes
bool WorldPhysicsSystem.AddWorld | ( | World | w | ) |
This method adds a new World to the physics system
This method will do nothing and provide a warning if the World w is null or already exists in the WorldPhysicsSystem.
This is the method by which you should add a World to the WorldPhysicsSystem.
w | The world to add |
bool WorldPhysicsSystem.AddWorldObject | ( | WorldObject | o | ) |
This method adds a new WorldObject to the physics system
This method will do nothing and provide a warning if the WorldObject o is null or already exists in the WorldPhysicsSystem.
This is the method by which you should add a WorldObject to the WorldPhysicsSystem.
o | The world to add |
bool WorldPhysicsSystem.GetGravityActive | ( | ) |
Returns if this system is active or not
float WorldPhysicsSystem.GetGravityDecay | ( | ) |
The retrieves the current gravitational decay rate
GravityMode WorldPhysicsSystem.GetGravityMode | ( | ) |
This gets the current gravity mode
float WorldPhysicsSystem.GetGravityScalar | ( | ) |
This retrieves the current gravity scalar of the system.
bool WorldPhysicsSystem.RemoveWorld | ( | World | w | ) |
This method removes a World from the physics system
This method will do nothing and provide a warning if the World w is null or does not exist in the WorldPhysicsSystem.
This is the method by which you should remove a World from the WorldPhysicsSystem. Note that this will not delete the object, so you must clean the memory manually.
w | The world to remove |
bool WorldPhysicsSystem.RemoveWorldObject | ( | WorldObject | o | ) |
This method removes a WorldObject from the physics system
This method will do nothing and provide a warning if the World w is null or does not exist in the WorldPhysicsSystem.
This is the method by which you should remove a World from the WorldPhysicsSystem. Note that this will not delete the object, so you must clean the memory manually.
w | The WorldObject to remove |
void WorldPhysicsSystem.SetGravityActive | ( | bool | b | ) |
Sets if the system is active
b | If true, this system will cause gravity. False otherwise. |
void WorldPhysicsSystem.SetGravityDecay | ( | float | decay | ) |
This sets the current gravitational decay rate
:: If the gravity mode is NOT set to GravityMode.ManualRate, this will produce a warning, as only manual mode can set this value. ::
decay | this is the new decay rate. Note that advised values are from 0 to 2. Outliers will have unpredictable results |
void WorldPhysicsSystem.SetGravityMode | ( | GravityMode | mode | ) |
This sets the gravity mode
The gravity can be set to any constant the in GravityMode enum. For details on what each value does, see the enum documentation.
:: Note that the arguments here must be proceeded as follows: WorldPhysicsSystem.GravityMode.ExampleMode ::
mode | The new GravityMode |
void WorldPhysicsSystem.SetGravityScalar | ( | float | scalar | ) |
This sets the gravity scalar for the system.
:: Note that negative and zero values are allowed. Negative creates repulsion fields, and zero effectively deactivates the system. ::
scalar | The new gravity scalar |
bool WorldPhysicsSystem.gravityActive = true |
A boolean which toggles if the gravity system is active or not.
GravSettings WorldPhysicsSystem.gravitySettings |
This wraps the settings of the gravity system
This is just a wrapper to allow tabs in the inspector. Gravity settings are contained in this structure.
List<WorldObject> WorldPhysicsSystem.worldObjects |
The list of WorldObjects in this system
This is the generic list which stores the WorldObjects present in the WorldPhysicsSystem. Though it is publicly modifiable, that is not recommended. Use the RemoveWorldObject(...) and AddWorldObject(...) methods to interact with this list in code and during runtime. It is public only so that it's contents can be easily viewed in the inspector/modified in inspector BEFORE runtime.
List<World> WorldPhysicsSystem.worlds |
The list of Worlds in this system
This is the generic list which stores the Worlds present in the WorldPhysicsSystem. Though it is publicly modifiable, that is not recommended. Use the RemoveWorld(...) and AddWorld(...) methods to interact with this list in code and during runtime. It is public only so that it's contents can be easily viewed in the inspector/modified in inspector BEFORE runtime.