C# Class UnityPlatformer.PlatformerCollider2D

Handle collisions with the world
Inheritance: RaycastController
Mostrar archivo Open project: llafuente/unity-platformer Class Usage Examples

Public Properties

Property Type Description
enableSlopes bool
maxClimbAngle float
maxDescendAngle float
minTranslation float
onLanding System.Action
onLeaveGround System.Action
onLeftWall System.Action
onRightWall System.Action
onTop System.Action
wallAngle float

Public Methods

Method Description
ClimbSlope ( Vector3 &velocity ) : void

Modify velocity to smooth climb current slope

ConsolidateCollisions ( ) : void

After all work, notify changes

DescendSlope ( Vector3 &velocity ) : void

Modify velocity to smooth descend current slope

DiagonalCollisions ( Vector3 &velocity ) : void

Unused. This may be redundant still experimental to fix some edge cases...

DisableLeaveGround ( ) : void

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

DisableSlopes ( float resetDelay = 0.5f ) : void

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.\n NOTE use it for jumping over a slope

EnableLeaveGround ( float resetDelay = 0.5f ) : void

leavingGround = true during resetDelay time

EnableSlopes ( ) : void

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

FallThroughPlatform ( float resetDelay = 0.5f ) : void

fallingThroughPlatform = true during resetDelay time

GetDownSlopeDir ( ) : Vector3

Vector pointing were to descend / slip

HorizontalCollisions ( RaycastHit2D &ray, Vector3 &velocity, int dir, int idx ) : void

Callback for ForeachLeftRay/ForeachRightRay

IsOnGround ( int graceFrames ) : bool

Collider is/was on ground. This is useful to give player some help, no pixel precision jumps :)

Move ( Vector3 velocity, float delta ) : Vector3

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.\n NOTE collisions.velocity has the real velocity applied

OnEnable ( ) : void
ResetFallingThroughPlatform ( ) : void

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

Start ( ) : void
UpdateCurrentSlope ( Vector3 velocity ) : void

Launch rays and get the maximum slope found

VerticalCollisions ( RaycastHit2D &ray, Vector3 &velocity, int dir, int idx ) : void

Callback for ForeachHeadRay/ForeachFeetRay

Method Details

ClimbSlope() public method

Modify velocity to smooth climb current slope
public ClimbSlope ( Vector3 &velocity ) : void
velocity Vector3 Amount to be moved
return void

ConsolidateCollisions() public method

After all work, notify changes
public ConsolidateCollisions ( ) : void
return void

DescendSlope() public method

Modify velocity to smooth descend current slope
public DescendSlope ( Vector3 &velocity ) : void
velocity Vector3 Amount to be moved
return void

DiagonalCollisions() public method

Unused. This may be redundant still experimental to fix some edge cases...
public DiagonalCollisions ( Vector3 &velocity ) : void
velocity Vector3 Amount to be moved
return void

DisableLeaveGround() public method

same as: 'leavingGround=false' to be used with: UpdateManager.SetTimeout
public DisableLeaveGround ( ) : void
return void

DisableSlopes() public method

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.\n NOTE use it for jumping over a slope
public DisableSlopes ( float resetDelay = 0.5f ) : void
resetDelay float 0 means no reset
return void

EnableLeaveGround() public method

leavingGround = true during resetDelay time
public EnableLeaveGround ( float resetDelay = 0.5f ) : void
resetDelay float 0 means no reset
return void

EnableSlopes() public method

same as: 'enableSlopes=true' to be used with: UpdateManager.SetTimeout
public EnableSlopes ( ) : void
return void

FallThroughPlatform() public method

fallingThroughPlatform = true during resetDelay time
public FallThroughPlatform ( float resetDelay = 0.5f ) : void
resetDelay float 0 means no reset
return void

GetDownSlopeDir() public method

Vector pointing were to descend / slip
public GetDownSlopeDir ( ) : Vector3
return Vector3

HorizontalCollisions() public method

Callback for ForeachLeftRay/ForeachRightRay
public HorizontalCollisions ( RaycastHit2D &ray, Vector3 &velocity, int dir, int idx ) : void
ray UnityEngine.RaycastHit2D result of Raycast horizontally
velocity Vector3 Amount to be moved
dir int Direction
idx int ray index
return void

IsOnGround() public method

Collider is/was on ground. This is useful to give player some help, no pixel precision jumps :)
public IsOnGround ( int graceFrames ) : bool
graceFrames int 0 means current frame
return bool

Move() public method

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.\n NOTE collisions.velocity has the real velocity applied
public Move ( Vector3 velocity, float delta ) : Vector3
velocity Vector3 Amount to be moved (velocity * delta)
delta float Time since last update
return Vector3

OnEnable() public method

public OnEnable ( ) : void
return void

ResetFallingThroughPlatform() public method

same as: 'fallingThroughPlatform=false' to be used with: UpdateManager.SetTimeout
public ResetFallingThroughPlatform ( ) : void
return void

Start() public method

public Start ( ) : void
return void

UpdateCurrentSlope() public method

Launch rays and get the maximum slope found
public UpdateCurrentSlope ( Vector3 velocity ) : void
velocity Vector3 Amount to be moved
return void

VerticalCollisions() public method

Callback for ForeachHeadRay/ForeachFeetRay
public VerticalCollisions ( RaycastHit2D &ray, Vector3 &velocity, int dir, int idx ) : void
ray UnityEngine.RaycastHit2D result of Raycast vertically
velocity Vector3 Amount to be moved
dir int Direction
idx int ray index
return void

Property Details

enableSlopes public_oe property

Enable slopes Slopes modify Y position of the collider, even when velocity is really X only, to give a smooth movement
public bool enableSlopes
return bool

maxClimbAngle public_oe property

Maximum angle the collider can walk-up
public float maxClimbAngle
return float

maxDescendAngle public_oe property

Maximum angle the collider can walk-down
public float maxDescendAngle
return float

minTranslation public_oe property

Prevent unwanted micro changes in orientation/falling. Makes the Collider more stable to changes.\n This is not a magnitude, handle X/Y separately
public float minTranslation
return float

onLanding public_oe property

Collider hit the ground
public Action,System onLanding
return System.Action

onLeaveGround public_oe property

Collider leave ground
public Action,System onLeaveGround
return System.Action

onLeftWall public_oe property

Collider hit a wall on left side
public Action,System onLeftWall
return System.Action

onRightWall public_oe property

Collider hit a wall on right side
public Action,System onRightWall
return System.Action

onTop public_oe property

Collider hit something with the 'Head'
public Action,System onTop
return System.Action

wallAngle public_oe property

Greater than wallAngle will be considered a Wall, not a slope
public float wallAngle
return float