All Classes Files Functions Variables Enumerations
Classes | Public Types | Public Member Functions | Public Attributes | List of all members
WorldPhysicsSystem Class Reference

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< Worldworlds
List< WorldObjectworldObjects

Detailed Description

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.

Member Enumeration Documentation

This enumeration defines various gravity modes

See Also
GravSettings.gravityMode
Enumerator:
Constant 

This mode applies no change of gravity over distance.

Realistic 

This mode applies gravity as it actually functions in the real world. This is an exponential decay over distance.

Linear 

This creates a linear drop off rate for strength of gravity over distance.

ManualRate 

This manually sets the rate of drop off for the gravity system. Less than zero is logarithmic, one is linear, and 2 is true realistic gravity. Perhaps useful, but be careful.

Member Function Documentation

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.

Parameters
wThe world to add
Returns
False if the World w is invalid, true if successful
See Also
RemoveWorld
worlds
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.

Parameters
oThe world to add
Returns
False if the WorldObject o is invalid, true if successful
See Also
RemoveWorldObject
worldObjects
bool WorldPhysicsSystem.GetGravityActive ( )

Returns if this system is active or not

Returns
True if this system is causing gravity, false otherwise.
See Also
gravityActive
SetGravityActive
float WorldPhysicsSystem.GetGravityDecay ( )

The retrieves the current gravitational decay rate

Returns
The current value of the gravitational decay rate
See Also
SetGravityDecay
GravSettings.distanceDecay
GravityMode WorldPhysicsSystem.GetGravityMode ( )

This gets the current gravity mode

Returns
GravityMode The current GravityMode
See Also
gravitySettings.gravityMode
SetGravityMode
GravityMode
float WorldPhysicsSystem.GetGravityScalar ( )

This retrieves the current gravity scalar of the system.

Returns
The current gravity scalar
See Also
gravitySettings.gravityScalar
SetGravityScalar
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.

Parameters
wThe world to remove
Returns
False if the World w is invalid, true if successful
See Also
AddWorld
worlds
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.

Parameters
wThe WorldObject to remove
Returns
False if the WorldObject o is invalid, true if successful
See Also
AddWorldObject
worldObjects
void WorldPhysicsSystem.SetGravityActive ( bool  b)

Sets if the system is active

Parameters
bIf true, this system will cause gravity. False otherwise.
See Also
gravityActive
GetGravityActive
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. ::

Parameters
decaythis is the new decay rate. Note that advised values are from 0 to 2. Outliers will have unpredictable results
See Also
GetGravityDecay
GravSettings.distanceDecay
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 ::

Parameters
modeThe new GravityMode
See Also
GravityMode
GetGravityMode
GravSettings.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. ::

Parameters
scalarThe new gravity scalar
See Also
GravSettings.gravityScalar
GetGravityScalar

Member Data Documentation

bool WorldPhysicsSystem.gravityActive = true

A boolean which toggles if the gravity system is active or not.

See Also
SetGravityActive
GetGravityActive
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.

See Also
RemoveWorldObject()
AddWorldObject()
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.

See Also
RemoveWorld()
AddWorld()

The documentation for this class was generated from the following file: