C# Class Nez.ArcadeRigidbody

Note that this is not a full, multi-iteration physics system! This can be used for simple, arcade style physics. Based on http://elancev.name/oliver/2D%20polygon.htm#tut5
Inheritance: Component, IUpdatable
Show file Open project: prime31/Nez Class Usage Examples

Public Properties

Property Type Description
shouldUseGravity bool
velocity Vector2

Public Methods

Method Description
ArcadeRigidbody ( ) : System
IUpdatable ( ) : void
addImpulse ( Vector2 force ) : void

add an instant force impulse to the rigidbody using its mass. force is an acceleration in pixels per second per second. The force is multiplied by 100000 to make the values more reasonable to use.

calculateResponseVelocity ( Vector2 &relativeVelocity, Vector2 &minimumTranslationVector, Vector2 &responseVelocity ) : void

given the relative velocity between the two objects and the MTV this method modifies the relativeVelocity to make it a collision response.

onAddedToEntity ( ) : void
processCollision ( ArcadeRigidbody other, Vector2 &minimumTranslationVector ) : void

handles the collision of two non-overlapping rigidbodies. New velocities will be assigned to each rigidbody as appropriate.

processOverlap ( ArcadeRigidbody other, Vector2 &minimumTranslationVector ) : void

separates two overlapping rigidbodies. Handles the case of either being immovable as well.

setElasticity ( float value ) : ArcadeRigidbody

0 - 1 range where 0 is no bounce and 1 is perfect reflection

setFriction ( float value ) : ArcadeRigidbody

0 - 1 range. 0 means no friction, 1 means the object will stop dead on

setGlue ( float value ) : ArcadeRigidbody

0 - 9 range. When a collision occurs and it has risidual motion along the surface of collision if its square magnitude is less than glue friction will be set to the maximum for the collision resolution.

setMass ( float mass ) : ArcadeRigidbody

mass of this rigidbody. A 0 mass will make this an immovable object.

setVelocity ( Vector2 velocity ) : ArcadeRigidbody

velocity of this rigidbody

Method Details

ArcadeRigidbody() public method

public ArcadeRigidbody ( ) : System
return System

IUpdatable() public method

public IUpdatable ( ) : void
return void

addImpulse() public method

add an instant force impulse to the rigidbody using its mass. force is an acceleration in pixels per second per second. The force is multiplied by 100000 to make the values more reasonable to use.
public addImpulse ( Vector2 force ) : void
force Vector2 Force.
return void

calculateResponseVelocity() public method

given the relative velocity between the two objects and the MTV this method modifies the relativeVelocity to make it a collision response.
public calculateResponseVelocity ( Vector2 &relativeVelocity, Vector2 &minimumTranslationVector, Vector2 &responseVelocity ) : void
relativeVelocity Vector2 Relative velocity.
minimumTranslationVector Vector2 Minimum translation vector.
responseVelocity Vector2
return void

onAddedToEntity() public method

public onAddedToEntity ( ) : void
return void

processCollision() public method

handles the collision of two non-overlapping rigidbodies. New velocities will be assigned to each rigidbody as appropriate.
public processCollision ( ArcadeRigidbody other, Vector2 &minimumTranslationVector ) : void
other ArcadeRigidbody Other.
minimumTranslationVector Vector2
return void

processOverlap() public method

separates two overlapping rigidbodies. Handles the case of either being immovable as well.
public processOverlap ( ArcadeRigidbody other, Vector2 &minimumTranslationVector ) : void
other ArcadeRigidbody Other.
minimumTranslationVector Vector2
return void

setElasticity() public method

0 - 1 range where 0 is no bounce and 1 is perfect reflection
public setElasticity ( float value ) : ArcadeRigidbody
value float Value.
return ArcadeRigidbody

setFriction() public method

0 - 1 range. 0 means no friction, 1 means the object will stop dead on
public setFriction ( float value ) : ArcadeRigidbody
value float Value.
return ArcadeRigidbody

setGlue() public method

0 - 9 range. When a collision occurs and it has risidual motion along the surface of collision if its square magnitude is less than glue friction will be set to the maximum for the collision resolution.
public setGlue ( float value ) : ArcadeRigidbody
value float Value.
return ArcadeRigidbody

setMass() public method

mass of this rigidbody. A 0 mass will make this an immovable object.
public setMass ( float mass ) : ArcadeRigidbody
mass float Mass.
return ArcadeRigidbody

setVelocity() public method

velocity of this rigidbody
public setVelocity ( Vector2 velocity ) : ArcadeRigidbody
velocity Vector2 Velocity.
return ArcadeRigidbody

Property Details

shouldUseGravity public property

if true, Physics.gravity will be taken into account each frame
public bool shouldUseGravity
return bool

velocity public property

velocity of this rigidbody
public Vector2 velocity
return Vector2