platformer
Public Member Functions | Static Public Member Functions | Public Attributes | Properties | List of all members
UnityPlatformer.Character Class Reference

Base class for: Players, NPCs, enemies. More...

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

Public Member Functions

delegate void AreaChange (Areas before, Areas after)
 Area change callback type More...
 
delegate void InjuredCharacter (Damage dt, CharacterHealth to, Character character)
 Character is Injured callback type More...
 
delegate void StateChange (States before, States after)
 State change event callback type More...
 
delegate void CharacterMove (Character character, float delta)
 Character move callback type More...
 
virtual void Awake ()
 This method precalculate some vars, but those value could change. This need to be refactored. Maybe setters are the appropiate method to refactor this. More...
 
GetAction< T > ()
 Get CharacterAction by type More...
 
virtual void PlatformerUpdate (float delta)
 Managed update called by UpdateManager More...
 
virtual void LatePlatformerUpdate (float delta)
 Do nothing More...
 
bool IsOnState (States _state)
 Return if the Character is on given state More...
 
bool IsOnAnyState (States _state)
 Return if the Character is on any of the given states More...
 
bool IsOnArea (Areas _area)
 Return if the Character is on given area More...
 
void EnterStateGraceful (States a)
 EnterState if it's not already in it It a safe mechanism to not trigger the change More...
 
void ExitStateGraceful (States a)
 EnterState if it's not already in it It a safe mechanism to not trigger the change More...
 
void EnterState (States a, bool privcall=false)
 Notify that Character enter a new state. There are incompatible states, like jumping and falling, You don't need to handle those manually, we will exit any state needed here. More...
 
void ExitState (States a, bool privcall=false)
 Notify that Character enter a new state. There are incompatible states, like jumping and falling, You don't need to handle those manually, we will exit any state needed here. More...
 
void EnterArea (Areas a)
 Character enter given area More...
 
void ExitArea (Areas a)
 Character exit given area More...
 
virtual void OnDeath ()
 Event when player is dead More...
 
override void OnEnable ()
 sync UpdateManager More...
 
virtual void OnDisable ()
 sync UpdateManager More...
 
void SetOverrideAnimation (string animation, bool freeze)
 Override current animation with the one given. The animation will be entirely played, then it will ClearOverrideAnimation More...
 
void ClearOverrideAnimation ()
 nullify forceAnimation. to be used with UpdateManager.SetTimeout More...
 
bool IsGroundOnLeft (float rayLengthFactor, float delta, Vector3? vel=null)
 Tell you if there is something on the left side NOTE ray origin is raycastOrigins.bottomLeft More...
 
bool IsGroundOnRight (float rayLengthFactor, float delta, Vector3? vel=null)
 Tell you if there is something on the right side NOTE ray origin is raycastOrigins.bottomRight More...
 
void SetFacing (Facing f)
 Set faceDir manualy More...
 
void SetFacing (float x)
 Based on 'horizontal movement' More...
 
bool IsBox (Directions dir)
 Is there a box on given direction? More...
 
Box GetLowestBox (Directions dir)
 Get the lowest box (the one Character Pull/Push) More...
 
- Public Member Functions inherited from UnityPlatformer.PlatformerCollider2D
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...
 

Static Public Member Functions

static bool BitOn (int a, int b)
 shortcut: Is a bit on More...
 

Public Attributes

float fallingTime = 0.1f
 Delay before enter States.Falling. More...
 
float groundGraceTime = 0.05f
 Delay before exit States.OnGround. More...
 
float minVelocity = 0.05f
 Minimum velocity. This is not a magnitude. More...
 
AreaChange onAreaChange
 Area change event (enter or leave) More...
 
InjuredCharacter onInjuredCharacter
 Character is Injured More...
 
StateChange onStateChange
 State change event (enter or leave) More...
 
CharacterMove onBeforeMove
 Before character move event More...
 
CharacterMove onAfterMove
 After character move event More...
 
List< CharacterActionactions = new List<CharacterAction>()
 List of enabled actions More...
 
Facing faceDir
 Where is facing More...
 
bool turnAllowed = true
 faceDir change is allowed?
This is used at melee attack so when you start an attack character don't turn and attack both sides at the same time. More...
 
States state = States.None
 Current states More...
 
Areas area = Areas.None
 Current areas More...
 
Fence fence
 Current fence More...
 
Ladder ladder
 Current ladder More...
 
Ladder ladderBottom
 Ladder at Character feet More...
 
Liquid liquid
 Current liquid More...
 
Item item
 Current reachable item More...
 
Grab grab
 Current Grab area More...
 
Rope rope
 Current Rope More...
 
int ropeIndex = -1
 Current RopeSection index More...
 
TrackData track
 Current Track More...
 
MovingPlatform platform
 Current MovingPlatform More...
 
Vector3 velocity = Vector3.zero
 character velocity More...
 
Vector3 worldVelocity = Vector3.zero
 World velocity: wind, Track... More...
 
Vector3 movedLastFrame = Vector3.zero
 Amount moved in the last PlatformerUpdate More...
 
CharacterHealth health
 Cache CharacterHealth More...
 
HitBox enterAreas
 Cache HitBox More...
 
CharacterAnimator animator
 Cache CharacterAnimator More...
 
string forceAnimation
 Force to play this animation More...
 
float frozen = -1f
 Do not execute any Action, Character still moves, so set velocity to Vector3.zero if necesarry More...
 
Bounds colBounds
 Collision bound More...
 
CharacterAction lastAction
 last active action More...
 
CharacterAction meleeInProgress
 Melee attack in progress More...
 
- Public Attributes inherited from UnityPlatformer.PlatformerCollider2D
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 lastJumpDistance [get]
 Last jump distance More...
 
Vector2 lastFallDistance [get]
 Last fall distance More...
 
Vector2 head [get]
 Character head position More...
 
Vector2 feet [get]
 Character feet position More...
 
- Properties inherited from UnityPlatformer.PlatformerCollider2D
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

Base class for: Players, NPCs, enemies.

Handle all movement logic and transform collider information into 'readable' information for animations.

NOTE executionOrder should be -25

Member Function Documentation

◆ AreaChange()

delegate void UnityPlatformer.Character.AreaChange ( Areas  before,
Areas  after 
)

Area change callback type

◆ Awake()

virtual void UnityPlatformer.Character.Awake ( )
inlinevirtual

This method precalculate some vars, but those value could change. This need to be refactored. Maybe setters are the appropiate method to refactor this.

◆ BitOn()

static bool UnityPlatformer.Character.BitOn ( int  a,
int  b 
)
inlinestatic

shortcut: Is a bit on

◆ CharacterMove()

delegate void UnityPlatformer.Character.CharacterMove ( Character  character,
float  delta 
)

Character move callback type

◆ ClearOverrideAnimation()

void UnityPlatformer.Character.ClearOverrideAnimation ( )
inline

nullify forceAnimation. to be used with UpdateManager.SetTimeout

◆ EnterArea()

void UnityPlatformer.Character.EnterArea ( Areas  a)
inline

Character enter given area

◆ EnterState()

void UnityPlatformer.Character.EnterState ( States  a,
bool  privcall = false 
)
inline

Notify that Character enter a new state. There are incompatible states, like jumping and falling, You don't need to handle those manually, we will exit any state needed here.

Parameters
aState to enter.
privcallDo call callbacks, changes will be batch into one call.

◆ EnterStateGraceful()

void UnityPlatformer.Character.EnterStateGraceful ( States  a)
inline

EnterState if it's not already in it It a safe mechanism to not trigger the change

◆ ExitArea()

void UnityPlatformer.Character.ExitArea ( Areas  a)
inline

Character exit given area

◆ ExitState()

void UnityPlatformer.Character.ExitState ( States  a,
bool  privcall = false 
)
inline

Notify that Character enter a new state. There are incompatible states, like jumping and falling, You don't need to handle those manually, we will exit any state needed here.

Parameters
aState to enter.
privcallDo call callbacks, changes will be batch into one call.

◆ ExitStateGraceful()

void UnityPlatformer.Character.ExitStateGraceful ( States  a)
inline

EnterState if it's not already in it It a safe mechanism to not trigger the change

◆ GetAction< T >()

T UnityPlatformer.Character.GetAction< T > ( )
inline

Get CharacterAction by type

◆ GetLowestBox()

Box UnityPlatformer.Character.GetLowestBox ( Directions  dir)
inline

Get the lowest box (the one Character Pull/Push)

◆ InjuredCharacter()

delegate void UnityPlatformer.Character.InjuredCharacter ( Damage  dt,
CharacterHealth  to,
Character  character 
)

Character is Injured callback type

◆ IsBox()

bool UnityPlatformer.Character.IsBox ( Directions  dir)
inline

Is there a box on given direction?

◆ IsGroundOnLeft()

bool UnityPlatformer.Character.IsGroundOnLeft ( float  rayLengthFactor,
float  delta,
Vector3?  vel = null 
)
inline

Tell you if there is something on the left side NOTE ray origin is raycastOrigins.bottomLeft

◆ IsGroundOnRight()

bool UnityPlatformer.Character.IsGroundOnRight ( float  rayLengthFactor,
float  delta,
Vector3?  vel = null 
)
inline

Tell you if there is something on the right side NOTE ray origin is raycastOrigins.bottomRight

◆ IsOnAnyState()

bool UnityPlatformer.Character.IsOnAnyState ( States  _state)
inline

Return if the Character is on any of the given states

◆ IsOnArea()

bool UnityPlatformer.Character.IsOnArea ( Areas  _area)
inline

Return if the Character is on given area

◆ IsOnState()

bool UnityPlatformer.Character.IsOnState ( States  _state)
inline

Return if the Character is on given state

◆ LatePlatformerUpdate()

virtual void UnityPlatformer.Character.LatePlatformerUpdate ( float  delta)
inlinevirtual

◆ OnDeath()

virtual void UnityPlatformer.Character.OnDeath ( )
inlinevirtual

Event when player is dead

Reimplemented in UnityPlatformer.StaticCharacter.

◆ OnDisable()

virtual void UnityPlatformer.Character.OnDisable ( )
inlinevirtual

sync UpdateManager

Reimplemented in UnityPlatformer.Enemy.

◆ OnEnable()

override void UnityPlatformer.Character.OnEnable ( )
inlinevirtual

sync UpdateManager

Reimplemented from UnityPlatformer.RaycastController.

Reimplemented in UnityPlatformer.Enemy.

◆ PlatformerUpdate()

virtual void UnityPlatformer.Character.PlatformerUpdate ( float  delta)
inlinevirtual

Managed update called by UpdateManager

Call all actions ask them who 'WantsToUpdate'
The highest priority action what want GainControl and PerformAction
Given action give a list of things to do after using GetPostUpdateActions
When all is done, fire events

Implements UnityPlatformer.IUpdateEntity.

Reimplemented in UnityPlatformer.AIJumper, UnityPlatformer.AICannon, and UnityPlatformer.StaticCharacter.

◆ SetFacing() [1/2]

void UnityPlatformer.Character.SetFacing ( Facing  f)
inline

Set faceDir manualy

◆ SetFacing() [2/2]

void UnityPlatformer.Character.SetFacing ( float  x)
inline

Based on 'horizontal movement'

◆ SetOverrideAnimation()

void UnityPlatformer.Character.SetOverrideAnimation ( string  animation,
bool  freeze 
)
inline

Override current animation with the one given. The animation will be entirely played, then it will ClearOverrideAnimation

◆ StateChange()

delegate void UnityPlatformer.Character.StateChange ( States  before,
States  after 
)

State change event callback type

Member Data Documentation

◆ actions

List<CharacterAction> UnityPlatformer.Character.actions = new List<CharacterAction>()

List of enabled actions

NOTE Each CharacterAction must sync with it's character

◆ animator

CharacterAnimator UnityPlatformer.Character.animator

◆ area

Areas UnityPlatformer.Character.area = Areas.None

Current areas

◆ colBounds

Bounds UnityPlatformer.Character.colBounds

Collision bound

◆ enterAreas

HitBox UnityPlatformer.Character.enterAreas

Cache HitBox

◆ faceDir

Facing UnityPlatformer.Character.faceDir

Where is facing

◆ fallingTime

float UnityPlatformer.Character.fallingTime = 0.1f

Delay before enter States.Falling.

◆ fence

Fence UnityPlatformer.Character.fence

Current fence

◆ forceAnimation

string UnityPlatformer.Character.forceAnimation

Force to play this animation

◆ frozen

float UnityPlatformer.Character.frozen = -1f

Do not execute any Action, Character still moves, so set velocity to Vector3.zero if necesarry

NOTE Even frozen, forceAnimation works...

◆ grab

Grab UnityPlatformer.Character.grab

Current Grab area

◆ groundGraceTime

float UnityPlatformer.Character.groundGraceTime = 0.05f

Delay before exit States.OnGround.

◆ health

CharacterHealth UnityPlatformer.Character.health

◆ item

Item UnityPlatformer.Character.item

Current reachable item

◆ ladder

Ladder UnityPlatformer.Character.ladder

Current ladder

◆ ladderBottom

Ladder UnityPlatformer.Character.ladderBottom

Ladder at Character feet

◆ lastAction

CharacterAction UnityPlatformer.Character.lastAction

last active action

◆ liquid

Liquid UnityPlatformer.Character.liquid

Current liquid

◆ meleeInProgress

CharacterAction UnityPlatformer.Character.meleeInProgress

Melee attack in progress

◆ minVelocity

float UnityPlatformer.Character.minVelocity = 0.05f

Minimum velocity. This is not a magnitude.

◆ movedLastFrame

Vector3 UnityPlatformer.Character.movedLastFrame = Vector3.zero

Amount moved in the last PlatformerUpdate

◆ onAfterMove

CharacterMove UnityPlatformer.Character.onAfterMove

After character move event

◆ onAreaChange

AreaChange UnityPlatformer.Character.onAreaChange

Area change event (enter or leave)

◆ onBeforeMove

CharacterMove UnityPlatformer.Character.onBeforeMove

Before character move event

◆ onInjuredCharacter

InjuredCharacter UnityPlatformer.Character.onInjuredCharacter

Character is Injured

◆ onStateChange

StateChange UnityPlatformer.Character.onStateChange

State change event (enter or leave)

◆ platform

MovingPlatform UnityPlatformer.Character.platform

Current MovingPlatform

◆ rope

Rope UnityPlatformer.Character.rope

Current Rope

◆ ropeIndex

int UnityPlatformer.Character.ropeIndex = -1

Current RopeSection index

◆ state

States UnityPlatformer.Character.state = States.None

Current states

◆ track

TrackData UnityPlatformer.Character.track

Current Track

◆ turnAllowed

bool UnityPlatformer.Character.turnAllowed = true

faceDir change is allowed?
This is used at melee attack so when you start an attack character don't turn and attack both sides at the same time.

◆ velocity

Vector3 UnityPlatformer.Character.velocity = Vector3.zero

character velocity

NOTE Character real velocity is velocity + worldVelocity

◆ worldVelocity

Vector3 UnityPlatformer.Character.worldVelocity = Vector3.zero

World velocity: wind, Track...

NOTE Character real velocity is velocity + worldVelocity

Property Documentation

◆ feet

Vector2 UnityPlatformer.Character.feet
get

Character feet position

◆ head

Vector2 UnityPlatformer.Character.head
get

Character head position

◆ lastFallDistance

Vector2 UnityPlatformer.Character.lastFallDistance
get

Last fall distance

◆ lastJumpDistance

Vector2 UnityPlatformer.Character.lastJumpDistance
get

Last jump distance


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