Show / Hide Table of Contents

Class PlatformerMotor2D

Inheritance
System.Object
PlatformerMotor2D
Namespace: Edgar.Unity.Examples.PC2D
Assembly: cs.temp.dll.dll
Syntax
public class PlatformerMotor2D : MonoBehaviour

Fields

additionalRaycastsPerSide

When checking for moving platforms that may have moved into the motor the corners are automatically casted on. This variable impacts how many more casts are made to each side. If the smallest size environment is the same size or bigger than the motor (width and height) then this can be 0. If it's at least half size then this can be 1. Increasing this number allows separation from smaller platform pieces but at a performance cost.

Declaration
public int additionalRaycastsPerSide
Field Value
Type Description
System.Int32

airSpeed

The maximum horizontal speed of the motor in the air.

Declaration
public float airSpeed
Field Value
Type Description
System.Single

airStopDistance

The distance the motor will 'slide' to a stop while in the air. Only effects horizontal movement.

Declaration
public float airStopDistance
Field Value
Type Description
System.Single

angleAllowedForMoving

The angle of slope the motor is allowed to walk on. It could be a good idea to keep this slightly above the minimum.

Declaration
public float angleAllowedForMoving
Field Value
Type Description
System.Single

changeDirectionInAir

If true, then the player can change x direction while jumping. If false, then the x velocity when leaving the ground will be held while in the air

Declaration
public bool changeDirectionInAir
Field Value
Type Description
System.Boolean

changeSpeedOnSlopes

Should the speed of the motor change depending of the angle of the slope. This only impacts walking on slopes, not while sliding.

Declaration
public bool changeSpeedOnSlopes
Field Value
Type Description
System.Boolean

cornerDistanceCheck

This is the size of the corner check. This can be tweaked with if corner grabs are not working correctly.

Declaration
public float cornerDistanceCheck
Field Value
Type Description
System.Single

cornerGrabDuration

The duration, in seconds, that the motor will stick to a corner.

Declaration
public float cornerGrabDuration
Field Value
Type Description
System.Single

cornerJumpMultiplier

The jump speed multiplier when jumping from a corner grab. Useful to forcing bigger jumps.

Declaration
public float cornerJumpMultiplier
Field Value
Type Description
System.Single

dashCooldown

When the motor will be allowed to dash again after dashing. The cooldown begins at the end of a dash.

Declaration
public float dashCooldown
Field Value
Type Description
System.Single

dashDistance

How far the motor will dash.

Declaration
public float dashDistance
Field Value
Type Description
System.Single

dashDuration

How long the dash lasts in seconds.

Declaration
public float dashDuration
Field Value
Type Description
System.Single

dashEasingFunction

The easing function used during the dash. Pick 'Linear' for just a set speed.

Declaration
public EasingFunctions.Functions dashEasingFunction
Field Value
Type Description
EasingFunctions.Functions

distanceToCheckToStick

If stickOnGround is true then the motor will search down for the ground to place itself on. This is how far it is willing to check. This needs to be high enough to account for the distance placed by the motor speed but should be smaller than the difference between environment heights. Play around until a nice value is found.

Declaration
public float distanceToCheckToStick
Field Value
Type Description
System.Single

enableCornerGrabs

Are corner grabs allowed? A corner grab is when the motor sticks to a corner.

Declaration
public bool enableCornerGrabs
Field Value
Type Description
System.Boolean

enableDashes

Is dashing allowed?

Declaration
public bool enableDashes
Field Value
Type Description
System.Boolean

enableOneWayPlatforms

Should the motor check for one way platforms? Set this to false if there aren't any, the motor will be more efficient. This will only have an effect if the motor's collider can't collide with its own layer. If it can then setting this to false won't help, one way platforms or not.

Declaration
public bool enableOneWayPlatforms
Field Value
Type Description
System.Boolean

enableSlopes

Should the motor check for any slopes? Set this to false if there are no slopes, the motor will be more efficient.

Declaration
public bool enableSlopes
Field Value
Type Description
System.Boolean

enableWallJumps

If wall jumps are allowed.

Declaration
public bool enableWallJumps
Field Value
Type Description
System.Boolean

enableWallSlides

If wall slides are allowed. A wall slide is when a motor slides down a wall. This will only take in effect once the stick is over.

Declaration
public bool enableWallSlides
Field Value
Type Description
System.Boolean

enableWallSticks

If wall sticking is allowed. A wall sticking is when a motor will 'grab' a wall.

Declaration
public bool enableWallSticks
Field Value
Type Description
System.Boolean

endDashNoGravityDuration

Delay (in seconds) before gravity is turned back on after a dash.

Declaration
public float endDashNoGravityDuration
Field Value
Type Description
System.Single

envCheckDistance

How far out the motor will check for the environment mask. This value can be tweaked if jump checks are not firing when wanted.

Declaration
public float envCheckDistance
Field Value
Type Description
System.Single

extraJumpHeight

The extra height the motor will jump if jump is 'held' down.

Declaration
public float extraJumpHeight
Field Value
Type Description
System.Single

fallSpeed

The maximum speed that the motor will fall. Only effects vertical speed when falling.

Declaration
public float fallSpeed
Field Value
Type Description
System.Single

fastFallGravityMultiplier

If the motor is in 'fast fall' then the gravityMultiplier is multiplied by the value. Higher number means faster acceleration while falling.

Declaration
public float fastFallGravityMultiplier
Field Value
Type Description
System.Single

fastFallSpeed

The maximum speed that the motor will fall during 'fast fall'.

Declaration
public float fastFallSpeed
Field Value
Type Description
System.Single

gravityMultiplier

Gravity multiplier to the Physics2D.gravity setting. Works like RigidBody2D's gravityMultiplier.

Declaration
public float gravityMultiplier
Field Value
Type Description
System.Single

groundSpeed

The maximum speed the motor will move on the ground, only effects horizontal speed.

Declaration
public float groundSpeed
Field Value
Type Description
System.Single

groundStopDistance

The distance the motor will slide to a stop from full speed while on the ground.

Declaration
public float groundStopDistance
Field Value
Type Description
System.Single

ignoreMovementAfterJump

After a corner or wall jump, this is how longer horizontal input is ignored.

Declaration
public float ignoreMovementAfterJump
Field Value
Type Description
System.Single

iterationDebug

Internal gizmos for iteration debugging.

Declaration
public bool iterationDebug
Field Value
Type Description
System.Boolean

jumpHeight

The height the motor will jump when a jump command is issued.

Declaration
public float jumpHeight
Field Value
Type Description
System.Single

jumpWindowWhenActivated

The grace period once the motor is told to jump where it will jump.

Declaration
public float jumpWindowWhenActivated
Field Value
Type Description
System.Single

jumpWindowWhenFalling

The amount of time once the motor has left an environment that a jump will be allowed.

Declaration
public float jumpWindowWhenFalling
Field Value
Type Description
System.Single

ladderSpeed

Maximum horizontal/vertical speed of the motor while climb a ladder

Declaration
public float ladderSpeed
Field Value
Type Description
System.Single

minDistanceFromEnv

The distance the motor will separate itself from environment. This is useful to prevent the motor from catching on edges.

Declaration
public float minDistanceFromEnv
Field Value
Type Description
System.Single

minimumSpeedToMoveUpSlipperySlope

The speed necessary to try running up a slope that's too steep. If speed is less than the minimum then the motor's velocity is zeroed out and the motor can't try to run up the slope.

Declaration
public float minimumSpeedToMoveUpSlipperySlope
Field Value
Type Description
System.Single

movingPlatformDebug

Internal gizmos moving platform debug rendering.

Declaration
public bool movingPlatformDebug
Field Value
Type Description
System.Boolean

movingPlatformLayerMask

The layer that contains moving platforms. If there are no moving platforms then make sure this has no layers (value of 0). Optimizations are made in the motor if it isn't expecting any moving platforms.

Declaration
public LayerMask movingPlatformLayerMask
Field Value
Type Description
LayerMask

normalizedValidWallInteraction

This is the size of a valid check (normalized to collider height) that will consider wall interactions valid. Starts from the top of the collider and moves down.

Declaration
public float normalizedValidWallInteraction
Field Value
Type Description
System.Single

numOfAirJumps

Number of air jumps allowed.

Declaration
public int numOfAirJumps
Field Value
Type Description
System.Int32

numOfIterations

The number of iterations the motor is allowed to make during the fixed update. Lower number will be more performant at a cost of losing some movement when collisions occur.

Declaration
public int numOfIterations
Field Value
Type Description
System.Int32

onAirJump

Delegate to attach to when the motor air jumps (called before onJump).

Declaration
public Action onAirJump
Field Value
Type Description
Action

onCornerJump

Delegate to attach to when the motor corner jumps (called before onJump).

Declaration
public Action onCornerJump
Field Value
Type Description
Action

onDash

Delegate to attach to when the motor dashes.

Declaration
public Action onDash
Field Value
Type Description
Action

onDashEnd

Delegate to attach to when the motor's dash ends.

Declaration
public Action onDashEnd
Field Value
Type Description
Action

oneWayPlatformsAreWalls

if enableOneWayPlatforms is disabled how the motor should treat OWP? when both are disabled, OWP are ignored from collisions.

Declaration
public bool oneWayPlatformsAreWalls
Field Value
Type Description
System.Boolean

onJump

Delegate to attach to when the motor jumps (ALL JUMPS!).

Declaration
public Action onJump
Field Value
Type Description
Action

onJumpEnd

Delegate that notifies, before change state, last jump has ended, reached the maximum allowed. Do not has parity with onJump, this is called when the last Jump ends not when Jump again.

Declaration
public Action onJumpEnd
Field Value
Type Description
Action

onLanded

Delegate that notifies that the motor has landed. amountFallen can be queried for distance fallen.

Declaration
public Action onLanded
Field Value
Type Description
Action

onSlipping

Delegate that notifies that the motor start slipping.

Declaration
public Action onSlipping
Field Value
Type Description
Action

onSlippingEnd

Delegate that notifies, before change state, that the motor end sliping.

Declaration
public Action onSlippingEnd
Field Value
Type Description
Action

onWallJump

Delegate to attach to when the motor walls jumps (called before onJump). The vector passed is the normal of the wall.

Declaration
public Action<Vector2> onWallJump
Field Value
Type Description
Action<Vector2>

slopeNormal

The normal of the slope the motor is on. This value doesn't have meaning unless onSlope is true.

Declaration
public Vector2 slopeNormal
Field Value
Type Description
Vector2

speedMultiplierOnSlope

If the motor changes speed on slopes then this acts as a multiplier. Lower values will mean bigger slow downs. A value of 1 means that it's only based off of the angle of the slope.

Declaration
public float speedMultiplierOnSlope
Field Value
Type Description
System.Single

staticEnvLayerMask

The static environment check mask. This should only be environment that doesn't move.

Declaration
public LayerMask staticEnvLayerMask
Field Value
Type Description
LayerMask

stickOnGround

Should the motor stick to the ground when walking down onto a slope or up over a slope? Otherwise the motor may fall onto the slope or have a slight hop when moving up over a slope.

Declaration
public bool stickOnGround
Field Value
Type Description
System.Boolean

timeToAirSpeed

The time it takes to move from zero horizontal speed to the maximum speed. This value is used to calculate the acceleration.

Declaration
public float timeToAirSpeed
Field Value
Type Description
System.Single

timeToGroundSpeed

How much time does it take for the motor to get from zero speed to max speed. This value is used to calculate the acceleration.

Declaration
public float timeToGroundSpeed
Field Value
Type Description
System.Single

timeToWallSlideSpeed

The time, in seconds, to get to wall slide speed.

Declaration
public float timeToWallSlideSpeed
Field Value
Type Description
System.Single

wallInteractionCooldown

Cooldown for allowing slides, sticks, and corner grabs. This may be necessary if the motor can slide down a vertical moving platform. If they don't exist then this can be 0.

Declaration
public float wallInteractionCooldown
Field Value
Type Description
System.Single

wallInteractionThreshold

The threshold that normalizedXMovement will have to be higher than to consider wall sticks, wall slides, wall jumps, and corner grabs.

Declaration
public float wallInteractionThreshold
Field Value
Type Description
System.Single

wallJumpAngle

The angle (degrees) in which the motor will jump away from the wall. 0 is horizontal and 90 is straight up.

Declaration
public float wallJumpAngle
Field Value
Type Description
System.Single

wallJumpMultiplier

The jump speed multiplier when wall jumping. This is useful to force bigger jumps off of the wall.

Declaration
public float wallJumpMultiplier
Field Value
Type Description
System.Single

wallSlideSpeed

The speed that the motor will slide down the wall.

Declaration
public float wallSlideSpeed
Field Value
Type Description
System.Single

wallSticksDuration

The duration of the wall sticks in seconds. Set to a very large number to effectively allow permanent sticks.

Declaration
public float wallSticksDuration
Field Value
Type Description
System.Single

Properties

amountFallen

Returns the amount of distance the motor has fallen. Includes fallen fast distance.

Declaration
public float amountFallen { get; }
Property Value
Type Description
System.Single

amountFastFallen

Returns the amount of distance the motor has fallen fast.

Declaration
public float amountFastFallen { get; }
Property Value
Type Description
System.Single

amountJumpedFor

Returns the amount the motor has jumped. This ceases to keep calculating after the motor starts to come down.

Declaration
public float amountJumpedFor { get; }
Property Value
Type Description
System.Single

canDash

If the motor is currently able to dash.

Declaration
public bool canDash { get; }
Property Value
Type Description
System.Boolean

collidingAgainst

The surfaces the motor is currently colliding against.

Declaration
public PlatformerMotor2D.CollidedSurface collidingAgainst { get; }
Property Value
Type Description
PlatformerMotor2D.CollidedSurface

connectedPlatform

Returns the moving platform that the motor is coupled with. If null then no moving platform.

Declaration
public MovingPlatformMotor2D connectedPlatform { get; }
Property Value
Type Description
MovingPlatformMotor2D

dashDirection

Returns the direction of the current dash. If not dashing then returns Vector2.zero.

Declaration
public Vector2 dashDirection { get; }
Property Value
Type Description
Vector2

dashDistanceCalculated

This is the distance calculated for dashed. Not be confused with distanceDashed. This doesn't care if the motor has hit a wall.

Declaration
public float dashDistanceCalculated { get; }
Property Value
Type Description
System.Single

distanceDashed

Returns the amount of distance dashed. If not dashing then returns 0.

Declaration
public float distanceDashed { get; }
Property Value
Type Description
System.Single

facingLeft

Since the motor needs to know the facing of the object, this information is made available to anyone else who might need it.

Declaration
public bool facingLeft { get; set; }
Property Value
Type Description
System.Boolean

fallFast

Set this true to have the motor fall faster. Set to false to fall at normal speeds.

Declaration
public bool fallFast { get; set; }
Property Value
Type Description
System.Boolean

frozen

Setting frozen to true will put the motor in a 'frozen' state. All information will be saved and set once unfrozen (the motor also reduces gravity to 0).

Note: This isn't a way to turn off the motor. To turn off the motor, simply set the script to disabled. Note: No delegate (onXXX) will be called

Declaration
public bool frozen { get; set; }
Property Value
Type Description
System.Boolean

inArea

The Areas the motor is currently in.

Declaration
public PlatformerMotor2D.CollidedArea inArea { get; }
Property Value
Type Description
PlatformerMotor2D.CollidedArea

jumpingHeld

If jumpingHeld is set to true then the motor will jump further. Set to false if jumping isn't 'held'.

Declaration
public bool jumpingHeld { get; set; }
Property Value
Type Description
System.Boolean

ladderZone

Declaration
public PlatformerMotor2D.LadderZone ladderZone { get; }
Property Value
Type Description
PlatformerMotor2D.LadderZone

motorState

Call this to get state information about the motor. This will be information such as if the object is in the air or on the ground. This can be used to set the appropriate animations.

Declaration
public PlatformerMotor2D.MotorState motorState { get; }
Property Value
Type Description
PlatformerMotor2D.MotorState

normalizedXMovement

Set the x movement direction. This is multiplied by the max speed. -1 is full left, 1 is full right. Higher numbers will result in faster speed.

Declaration
public float normalizedXMovement { get; set; }
Property Value
Type Description
System.Single

normalizedYMovement

Set the y movement direction. This is multiplied by the max speed. -1 is full left, 1 is full right. Higher numbers will result in faster speed. Only used for ladders

Declaration
public float normalizedYMovement { get; set; }
Property Value
Type Description
System.Single

onSlope

Whether or not the motor is on a slope. This can be simply walking on a slope or slipping.

Declaration
public bool onSlope { get; }
Property Value
Type Description
System.Boolean

timeScale

Set the time scale for the motor. This is independent of the global time scale. Negative values are not supported.

Declaration
public float timeScale { get; set; }
Property Value
Type Description
System.Single

velocity

The velocity of the motor. This should be queried instead of the rigidbody's velocity. Setting this during a dash doesn't have any meaning.

Declaration
public Vector2 velocity { get; set; }
Property Value
Type Description
Vector2

Methods

ClearRestrictedArea()

Declaration
public void ClearRestrictedArea()

Dash()

Call this to have the motor try to dash, once called it will be handled in the FixedUpdate tick. This causes the object to dash along their facing (if left or right for side scrollers).

Declaration
public void Dash()

Dash(Vector2)

Send a direction vector to dash allow dashing in a specific direction.

Declaration
public void Dash(Vector2 dir)
Parameters
Type Name Description
Vector2 dir

The normalized direction of the dash.

DisableRestrictedArea()

Declaration
public void DisableRestrictedArea()

DisconnectFromPlatform()

Decouples the motor from the platform. This could be useful for a platform that throw the motor in the air. Call this when when the motor should disconnect then set the appropriate velocity.

Declaration
public void DisconnectFromPlatform()

EnableRestrictedArea()

Declaration
public void EnableRestrictedArea()

EndDash()

Call to end dash immediately.

Declaration
public void EndDash()

EndJump()

Call to end a jump. Causes the motor to stop calculated held speed for a jump.

Declaration
public void EndJump()

ForceDash()

Forces the motor to dash regardless if the motor thinks it is valid or not.

Declaration
public void ForceDash()

ForceDash(Vector2)

Forces a dash along a specified direction.

Declaration
public void ForceDash(Vector2 dir)
Parameters
Type Name Description
Vector2 dir

The normalized direction of the dash.

ForceJump()

This will force a jump to occur even if the motor doesn't think a jump is valid. This function will not work if the motor is dashing.

Declaration
public void ForceJump()

ForceJump(Single)

Force a jump with a custom height.

Declaration
public void ForceJump(float customHeight)
Parameters
Type Name Description
System.Single customHeight

The height the motor should jump to. The extraJumpHeight is still applicable.

FreedomAreaEnter()

Declaration
public void FreedomAreaEnter()

FreedomAreaExit()

Declaration
public void FreedomAreaExit()

FreedomStateEnter()

Declaration
public void FreedomStateEnter()

FreedomStateExit()

Declaration
public void FreedomStateExit()

IsDashing()

Is the motor Dashing?

Declaration
public bool IsDashing()
Returns
Type Description
System.Boolean

IsFalling()

is the motor falling? do not include failling fast.

Declaration
public bool IsFalling()
Returns
Type Description
System.Boolean

IsFallingFast()

is the motor falling fast? do not include failling (normal).

Declaration
public bool IsFallingFast()
Returns
Type Description
System.Boolean

IsForceSlipping()

Declaration
public bool IsForceSlipping()
Returns
Type Description
System.Boolean

IsGrounded()

Motor is standing on the floor. Does not include Sliding

Declaration
public bool IsGrounded()
Returns
Type Description
System.Boolean

IsInAir()

Motor is in mid air?

Declaration
public bool IsInAir()
Returns
Type Description
System.Boolean

IsJumping()

Is the motor Jumping? include walljumps and airjumps.

Declaration
public bool IsJumping()
Returns
Type Description
System.Boolean

IsMovingPlatform(GameObject)

Declaration
public bool IsMovingPlatform(GameObject obj)
Parameters
Type Name Description
GameObject obj
Returns
Type Description
System.Boolean

IsOnCorner()

Motor is on corner?

Declaration
public bool IsOnCorner()
Returns
Type Description
System.Boolean

IsOnFreedomArea()

Declaration
public bool IsOnFreedomArea()
Returns
Type Description
System.Boolean

IsOnGround()

Motor is standing onto something?

Declaration
public bool IsOnGround()
Returns
Type Description
System.Boolean

IsOnLadder()

Declaration
public bool IsOnLadder()
Returns
Type Description
System.Boolean

IsOnWall()

Motor is sticking on a wall or on corner or slidding on a wall.

Declaration
public bool IsOnWall()
Returns
Type Description
System.Boolean

IsRestricted()

Declaration
public bool IsRestricted()
Returns
Type Description
System.Boolean

IsSlipping()

Motor is Slipping?

Declaration
public bool IsSlipping()
Returns
Type Description
System.Boolean

IsStatic(GameObject)

Declaration
public bool IsStatic(GameObject obj)
Parameters
Type Name Description
GameObject obj
Returns
Type Description
System.Boolean

IsUserHandled()

is the motor Jumping? include walljumps and airjumps.

Declaration
public bool IsUserHandled()
Returns
Type Description
System.Boolean

IsWallSliding()

Motor is sliding on wall?

Declaration
public bool IsWallSliding()
Returns
Type Description
System.Boolean

IsWallSticking()

is the motor stick to a wall? Use PressingIntoLeftWall, PressingIntoRightWall to know what wall.

Declaration
public bool IsWallSticking()
Returns
Type Description
System.Boolean

Jump()

Call this to have the GameObject try to jump, once called it will be handled in the FixedUpdate tick. The y axis is considered jump.

Declaration
public void Jump()

Jump(Single)

Jump that allows a custom height.

Declaration
public void Jump(float customHeight)
Parameters
Type Name Description
System.Single customHeight

The height the motor should jump to. The extraJumpHeight is still applicable.

LadderAreaEnter(Bounds, Single, Single)

Declaration
public void LadderAreaEnter(Bounds area, float topHeight = 0F, float bottomHeight = 0F)
Parameters
Type Name Description
Bounds area
System.Single topHeight
System.Single bottomHeight

LadderAreaExit()

Declaration
public void LadderAreaExit()

ResetAirJump()

Resets the state for air jumps by setting the counter to 0.

Declaration
public void ResetAirJump()

ResetDashCooldown()

Reset the cooldown for dash.

Declaration
public void ResetDashCooldown()

SetLadderZone(PlatformerMotor2D.LadderZone)

Declaration
public void SetLadderZone(PlatformerMotor2D.LadderZone z)
Parameters
Type Name Description
PlatformerMotor2D.LadderZone z

SetRestrictedArea(Bounds, Boolean)

Declaration
public void SetRestrictedArea(Bounds b, bool disableTop = false)
Parameters
Type Name Description
Bounds b
System.Boolean disableTop
In This Article
Back to top Generated by DocFX