platformer
Classes | Public Member Functions | Public Attributes | Properties | List of all members
UnityPlatformer.PlatformerCollider2D Class Reference

Handle collisions with the world More...

Inheritance diagram for UnityPlatformer.PlatformerCollider2D:
UnityPlatformer.RaycastController UnityPlatformer.Character UnityPlatformer.Enemy UnityPlatformer.StaticCharacter UnityPlatformer.AICannon UnityPlatformer.AIPatrol UnityPlatformer.AIJumper

Classes

class  CollisionInfo
 Collision info More...
 
class  Contacts
 Contact class More...
 

Public Member Functions

override void Start ()
 Initialization More...
 
override void OnEnable ()
 More Initialization More...
 
bool IsMovingAgainstGravity (ref Vector3 velocity)
 Is character move against gravity More...
 
bool IsDirectionBelow (int dir)
 Returns if gravity has the same direction as dir More...
 
bool IsDirectionAbove (int dir)
 Returns if gravity has the opposite direction as dir More...
 
Vector3 Move (Vector3 velocity, float delta)
 Attempt to move the character to current position + velocity. More...
 
void DisableSlopes (float resetDelay=0.5f)
 Disable slopes, so no more ClimbSlope/DescendSlope More...
 
void EnableSlopes ()
 same as: 'enableSlopes=true' to be used with: UpdateManager.SetTimeout More...
 
void FallThroughPlatform (float resetDelay=0.5f)
 fallingThroughPlatform = true during resetDelay time More...
 
void ResetFallingThroughPlatform ()
 same as: 'fallingThroughPlatform=false' to be used with: UpdateManager.SetTimeout More...
 
void EnableLeaveGround (float resetDelay=0.5f)
 leavingGround = true during resetDelay time More...
 
void DisableLeaveGround ()
 same as: 'leavingGround=false' to be used with: UpdateManager.SetTimeout More...
 
bool IsOnGround (int graceFrames=0)
 Collider is/was on ground. More...
 
Vector3 GetDownSlopeDir ()
 Vector pointing were to descend / slip More...
 
void ConsolidateCollisions ()
 After all work, notify changes More...
 
- Public Member Functions inherited from UnityPlatformer.RaycastController
void UpdateInnerBounds ()
 Recalculate shrinked the bounds More...
 
void UpdateRaycastOrigins ()
 Recalculate raycastOrigins More...
 
void CalculateRaySpacing ()
 Recalculate distance between rays (horizontalRaySpacing & verticalRaySpacing) More...
 
RaycastHit2D Raycast (Vector2 origin, Vector2 direction, float rayLength, int mask, Color? color=null)
 Call Physics2D.Raycast and Draw the ray to debug More...
 
RaycastHit2D VerticalRay (float directionY, int index, float rayLength, ref Vector3 velocity, Color? c=null)
 Return RaycastHit2D of Raycasting at given index More...
 
RaycastHit2D FeetRay (float rayLength, LayerMask mask)
 Return RaycastHit2D of Raycasting at bottom center. More...
 
delegate void RayItr (ref RaycastHit2D hit, ref Vector3 velocity, int dir, int idx)
 Callback for iterate rays More...
 
void ForeachRightRay (float rayLength, ref Vector3 velocity, RayItr itr)
 Iterate over all right/horizontal rays More...
 
void ForeachLeftRay (float rayLength, ref Vector3 velocity, RayItr itr)
 Iterate over all left/horizontal rays More...
 
void ForeachHeadRay (float rayLength, ref Vector3 velocity, RayItr itr, bool checkGravitySwap=true)
 Iterate over all head/vertical rays More...
 
void ForeachFeetRay (float rayLength, ref Vector3 velocity, RayItr itr, bool checkGravitySwap=true)
 Iterate over all feet/vertical rays More...
 
Vector2 GetDownVector ()
 Return gravity aware down Vector2 More...
 
Vector3 GetBottomLeft ()
 Return gravity aware bottom left More...
 
Vector3 GetBottomRight ()
 Return gravity aware bottom right More...
 
RaycastHit2D LeftFeetRay (float rayLength, Vector3 velocity)
 Return RaycastHit2D of Raycasting at bottom left. More...
 
RaycastHit2D RightFeetRay (float rayLength, Vector3 velocity)
 Return RaycastHit2D of Raycasting at bottom right. More...
 

Public Attributes

Vector2 gravityOverride = Vector2.zero
 Override Configuration.gravity More...
 
Vector2 terminalVelocity = new Vector2(50, 25)
 Terminal velocity: maximum velocity that the PlatformerCollider2D could have. More...
 
float maxClimbAngle = 45.0f
 Maximum angle the collider can walk-up More...
 
float maxDescendAngle = 45.0f
 Maximum angle the collider can walk-down More...
 
float wallAngle = 89.9f
 Greater than wallAngle will be considered a Wall, not a slope More...
 
bool enableSlopes = true
 Enable slopes More...
 
float minTranslation = 0.01f
 Prevent unwanted micro changes in orientation/falling. More...
 
bool useRigidbody2D = false
 This is experimental staff, If we use RigidBody2D we are sure to never enter another object by accident and we handle less collisions but has many drawbacks, that can't be solved atm, like OneWayPlatforms More...
 
Action onRightWall
 Collider hit a wall on right side More...
 
Action onLeftWall
 Collider hit a wall on left side More...
 
Action onLanding
 Collider hit the ground More...
 
Action onLeaveGround
 Collider leave ground More...
 
Action onTop
 Collider hit something with the 'Head' More...
 
- Public Attributes inherited from UnityPlatformer.RaycastController
bool debug = false
 Enable drawing debug information, this has performance impact More...
 
LayerMask collisionMask
 Static geometry mask More...
 
float minDistanceToEnv = 0.1f
 How far from then env the Character must be. More...
 
float skinWidth = 0.2f
 Defines how far in from the edges of the collider rays are we going to cast from. More...
 
int horizontalRayCount = 4
 How many rays to check horizontal collisions More...
 
int verticalRayCount = 4
 How many rays to check vertical collisions More...
 
float height
 Collider real height More...
 
Vector3 localCenter
 Collider center in local space More...
 

Properties

Vector2 gravity [get]
 Retrievethe real gravity for this Collider More...
 
- Properties inherited from UnityPlatformer.RaycastController
Vector3 center [get]
 Collider center in world space More...
 

Detailed Description

Handle collisions with the world

Member Function Documentation

◆ ConsolidateCollisions()

void UnityPlatformer.PlatformerCollider2D.ConsolidateCollisions ( )
inline

After all work, notify changes

◆ DisableLeaveGround()

void UnityPlatformer.PlatformerCollider2D.DisableLeaveGround ( )
inline

same as: 'leavingGround=false' to be used with: UpdateManager.SetTimeout

◆ DisableSlopes()

void UnityPlatformer.PlatformerCollider2D.DisableSlopes ( float  resetDelay = 0.5f)
inline

Disable slopes, so no more ClimbSlope/DescendSlope

This is important, because while on slope, velocity.y will be modified If you need your velocity to remain, you must disable slopes.
NOTE use it for jumping over a slope

Parameters
resetDelay0 means no reset

◆ EnableLeaveGround()

void UnityPlatformer.PlatformerCollider2D.EnableLeaveGround ( float  resetDelay = 0.5f)
inline

leavingGround = true during resetDelay time

Parameters
resetDelay0 means no reset

◆ EnableSlopes()

void UnityPlatformer.PlatformerCollider2D.EnableSlopes ( )
inline

same as: 'enableSlopes=true' to be used with: UpdateManager.SetTimeout

◆ FallThroughPlatform()

void UnityPlatformer.PlatformerCollider2D.FallThroughPlatform ( float  resetDelay = 0.5f)
inline

fallingThroughPlatform = true during resetDelay time

Parameters
resetDelay0 means no reset

◆ GetDownSlopeDir()

Vector3 UnityPlatformer.PlatformerCollider2D.GetDownSlopeDir ( )
inline

Vector pointing were to descend / slip

◆ IsDirectionAbove()

bool UnityPlatformer.PlatformerCollider2D.IsDirectionAbove ( int  dir)
inline

Returns if gravity has the opposite direction as dir

◆ IsDirectionBelow()

bool UnityPlatformer.PlatformerCollider2D.IsDirectionBelow ( int  dir)
inline

Returns if gravity has the same direction as dir

◆ IsMovingAgainstGravity()

bool UnityPlatformer.PlatformerCollider2D.IsMovingAgainstGravity ( ref Vector3  velocity)
inline

Is character move against gravity

◆ IsOnGround()

bool UnityPlatformer.PlatformerCollider2D.IsOnGround ( int  graceFrames = 0)
inline

Collider is/was on ground.

This is useful to give player some help, no pixel precision jumps :)

Parameters
graceFrames0 means current frame

◆ Move()

Vector3 UnityPlatformer.PlatformerCollider2D.Move ( Vector3  velocity,
float  delta 
)
inline

Attempt to move the character to current position + velocity.

Any colliders in our way will cause velocity to be modified ex: wall -> stop. slope -> modifiy velocity.
NOTE collisions.velocity has the real velocity applied

Parameters
velocityAmount to be moved (velocity * delta)
deltaTime since last update
Returns
Real velocity after collisions

◆ OnEnable()

override void UnityPlatformer.PlatformerCollider2D.OnEnable ( )
inlinevirtual

More Initialization

Reimplemented from UnityPlatformer.RaycastController.

◆ ResetFallingThroughPlatform()

void UnityPlatformer.PlatformerCollider2D.ResetFallingThroughPlatform ( )
inline

same as: 'fallingThroughPlatform=false' to be used with: UpdateManager.SetTimeout

◆ Start()

override void UnityPlatformer.PlatformerCollider2D.Start ( )
inlinevirtual

Initialization

Reimplemented from UnityPlatformer.RaycastController.

Member Data Documentation

◆ enableSlopes

bool UnityPlatformer.PlatformerCollider2D.enableSlopes = true

Enable slopes

Slopes modify Y position of the collider, even when velocity is really X only, to give a smooth movement

◆ gravityOverride

Vector2 UnityPlatformer.PlatformerCollider2D.gravityOverride = Vector2.zero

◆ maxClimbAngle

float UnityPlatformer.PlatformerCollider2D.maxClimbAngle = 45.0f

Maximum angle the collider can walk-up

◆ maxDescendAngle

float UnityPlatformer.PlatformerCollider2D.maxDescendAngle = 45.0f

Maximum angle the collider can walk-down

◆ minTranslation

float UnityPlatformer.PlatformerCollider2D.minTranslation = 0.01f

Prevent unwanted micro changes in orientation/falling.

Makes the Collider more stable to changes.
This is not a magnitude, handle X/Y separately

◆ onLanding

Action UnityPlatformer.PlatformerCollider2D.onLanding

Collider hit the ground

◆ onLeaveGround

Action UnityPlatformer.PlatformerCollider2D.onLeaveGround

Collider leave ground

◆ onLeftWall

Action UnityPlatformer.PlatformerCollider2D.onLeftWall

Collider hit a wall on left side

◆ onRightWall

Action UnityPlatformer.PlatformerCollider2D.onRightWall

Collider hit a wall on right side

◆ onTop

Action UnityPlatformer.PlatformerCollider2D.onTop

Collider hit something with the 'Head'

◆ terminalVelocity

Vector2 UnityPlatformer.PlatformerCollider2D.terminalVelocity = new Vector2(50, 25)

Terminal velocity: maximum velocity that the PlatformerCollider2D could have.

NOTE: Character.worldVelocity is applied after this terminalVelocity

◆ useRigidbody2D

bool UnityPlatformer.PlatformerCollider2D.useRigidbody2D = false

This is experimental staff, If we use RigidBody2D we are sure to never enter another object by accident and we handle less collisions but has many drawbacks, that can't be solved atm, like OneWayPlatforms

◆ wallAngle

float UnityPlatformer.PlatformerCollider2D.wallAngle = 89.9f

Greater than wallAngle will be considered a Wall, not a slope

Property Documentation

◆ gravity

Vector2 UnityPlatformer.PlatformerCollider2D.gravity
get

Retrievethe real gravity for this Collider


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