Class Controller2D
A physics controller used to add custom physics logic to any object.
This physics controller adds the ability to invoke events when colliding on per direction basis by
using the CollisionController
Inheritance
System.Object
Controller2D
Assembly: cs.temp.dll.dll
Syntax
public class Controller2D : MonoBehaviour
Fields
_boxCollider
Declaration
protected BoxCollider2D _boxCollider
Field Value
Type |
Description |
BoxCollider2D |
|
_calculatedVelocity
The overall velocity to be added this frame.
Declaration
protected Vector2 _calculatedVelocity
Field Value
_direction
Declaration
protected Vector2 _direction
Field Value
_directionLastFrame
Declaration
protected Vector2 _directionLastFrame
Field Value
_externalVelocity
Velocity adding through external physics forces such as gravity and interactable objects.
Declaration
protected Vector2 _externalVelocity
Field Value
_previousDirection
Used to keep track of the direction to restore after unfreezing the Controller2D.
Declaration
protected Vector2 _previousDirection
Field Value
_rigidbody2D
Declaration
protected Rigidbody2D _rigidbody2D
Field Value
Type |
Description |
Rigidbody2D |
|
Bounds
Declaration
Field Value
CharacterState
Declaration
public CharacterState CharacterState
Field Value
CollisionController
Declaration
public CollisionController CollisionController
Field Value
Type |
Description |
CollisionController |
|
CollisionInfo
Declaration
public CollisionInfo CollisionInfo
Field Value
Type |
Description |
CollisionInfo |
|
CurrentPhysics
Declaration
public MovementProperties CurrentPhysics
Field Value
Type |
Description |
MovementProperties |
|
DefaultPhysics
Declaration
public MovementProperties DefaultPhysics
Field Value
Type |
Description |
MovementProperties |
|
DistanceToGround
Declaration
public float DistanceToGround
Field Value
Type |
Description |
System.Single |
|
IsFrozen
Declaration
Field Value
Type |
Description |
System.Boolean |
|
OnDirectionChanged
Declaration
public EventHandler<Vector2> OnDirectionChanged
Field Value
Type |
Description |
EventHandler<Vector2> |
|
PhysicsVolumeType
The type of PhysicsVolumeType the controller is in. Sets as none if not in one.
Declaration
public PhysicsVolumeType PhysicsVolumeType
Field Value
Type |
Description |
PhysicsVolumeType |
|
Declaration
public ContactFilter2D PlatformFilter
Field Value
Type |
Description |
ContactFilter2D |
|
ReferenceSpeed
Reference speed if used for passing in a value in horizontal calculatin based on running or not.
Declaration
public float ReferenceSpeed
Field Value
Type |
Description |
System.Single |
|
Properties
CollisionActivated
Declaration
public bool CollisionActivated { get; set; }
Property Value
Type |
Description |
System.Boolean |
|
Direction
Declaration
public Vector2 Direction { get; set; }
Property Value
Methods
AddHorizontalVelocity(Single)
Declaration
public virtual void AddHorizontalVelocity(float horizontalVelocity)
Parameters
Type |
Name |
Description |
System.Single |
horizontalVelocity |
|
AddVelocity(Vector2)
Declaration
public virtual void AddVelocity(Vector2 velocity)
Parameters
Type |
Name |
Description |
Vector2 |
velocity |
|
AddVerticalVelocity(Single)
Declaration
public virtual void AddVerticalVelocity(float verticalVelocity)
Parameters
Type |
Name |
Description |
System.Single |
verticalVelocity |
|
CalculateHorizontal()
Declaration
protected virtual void CalculateHorizontal()
CalculateMovementState()
Declaration
protected virtual void CalculateMovementState()
CalculateVertical()
Declaration
protected virtual void CalculateVertical()
CeilingChecks()
Declaration
protected virtual void CeilingChecks()
ChangeDirection()
Declaration
public void ChangeDirection()
CheckOnCollisionActions()
Checks to see what sides might have a new collision that was started the current frame. If a new collision is detected on the side invoke the action related to that sides collisions.
Declaration
protected virtual void CheckOnCollisionActions()
ColisionChecks()
Declaration
protected virtual void ColisionChecks()
CorrectCollisionClipping()
If the transform translate puts us through a collider do to a off update frame for movement than correct the transform to prevent overlapping.
Declaration
protected virtual void CorrectCollisionClipping()
DebugBoxCast(Vector2, Vector2, Single, Vector2, Single, LayerMask)
Declaration
protected RaycastHit2D DebugBoxCast(Vector2 origin, Vector2 size, float angle, Vector2 direction, float distance, LayerMask layerMask)
Parameters
Type |
Name |
Description |
Vector2 |
origin |
|
Vector2 |
size |
|
System.Single |
angle |
|
Vector2 |
direction |
|
System.Single |
distance |
|
LayerMask |
layerMask |
|
Returns
Type |
Description |
RaycastHit2D |
|
DebugRayCast(Vector2, Vector2, Single, LayerMask)
Declaration
protected RaycastHit2D DebugRayCast(Vector2 origin, Vector2 direction, float distance, LayerMask layerMask)
Parameters
Type |
Name |
Description |
Vector2 |
origin |
|
Vector2 |
direction |
|
System.Single |
distance |
|
LayerMask |
layerMask |
|
Returns
Type |
Description |
RaycastHit2D |
|
FixedUpdate()
Declaration
protected virtual void FixedUpdate()
FreezeController()
Declaration
public void FreezeController()
GetColliderBounds()
This is called from external classes to get the current colliders bounds value when a boxcollider has not been set and had it's bounds cached yet. Useful for editor debugging.
Declaration
public Bounds GetColliderBounds()
Returns
GroundChecks()
Declaration
protected virtual void GroundChecks()
Init()
This runs before OnAwake code to make sure things needing Initialized are
ready before it is called and needed. This can be called externally if
the Controller ever needs reset. Think spawning a character.
Declaration
LowerToGround()
Declaration
protected void LowerToGround()
Move()
Declaration
protected virtual void Move()
OnAwake()
Declaration
protected virtual void OnAwake()
OnInit()
Declaration
protected virtual void OnInit()
OnLateUpdate()
Declaration
protected virtual void OnLateUpdate()
OnPreFixedUpdate()
Declaration
protected virtual void OnPreFixedUpdate()
OnStart()
Declaration
protected virtual void OnStart()
OnStatusEffectChanged(StatusEffect)
Declaration
protected void OnStatusEffectChanged(StatusEffect statusEffect)
Parameters
PositionCorection()
Corects the posiution if the character clips or goes through an object due to moving to fast during a frame.
Declaration
protected virtual void PositionCorection()
Declaration
public bool RaycastMultiple(Vector2 origin, Vector2 end, Vector2 direction, float distance, ContactFilter2D contactFilter2D, int numberOfRays = 4)
Parameters
Type |
Name |
Description |
Vector2 |
origin |
|
Vector2 |
end |
|
Vector2 |
direction |
|
System.Single |
distance |
|
ContactFilter2D |
contactFilter2D |
|
System.Int32 |
numberOfRays |
|
Returns
Type |
Description |
System.Boolean |
|
RaycastMultiple(Vector2, Vector2, Vector2, Single, LayerMask, Int32)
Declaration
public bool RaycastMultiple(Vector2 origin, Vector2 end, Vector2 direction, float distance, LayerMask layerMask, int numberOfRays = 4)
Parameters
Type |
Name |
Description |
Vector2 |
origin |
|
Vector2 |
end |
|
Vector2 |
direction |
|
System.Single |
distance |
|
LayerMask |
layerMask |
|
System.Int32 |
numberOfRays |
|
Returns
Type |
Description |
System.Boolean |
|
Reset()
Declaration
public virtual void Reset()
ResetPhysics(MovementProperties)
Declaration
public virtual void ResetPhysics(MovementProperties movementProperties)
Parameters
Type |
Name |
Description |
MovementProperties |
movementProperties |
|
SetDirection(Single)
Declaration
public void SetDirection(float newDirection)
Parameters
Type |
Name |
Description |
System.Single |
newDirection |
|
SetDirectionalForce(Vector2)
This function applies velocity compared to the direction the user is facing.
Declaration
public virtual void SetDirectionalForce(Vector2 force)
Parameters
Type |
Name |
Description |
Vector2 |
force |
|
SetExternalVelocity(Vector2)
Declaration
public void SetExternalVelocity(Vector2 force)
Parameters
Type |
Name |
Description |
Vector2 |
force |
|
SetHorizontalVelocity(Single)
Declaration
public virtual void SetHorizontalVelocity(float horizontalVelocity)
Parameters
Type |
Name |
Description |
System.Single |
horizontalVelocity |
|
SetVelocity(Vector2)
Declaration
public virtual void SetVelocity(Vector2 velocity)
Parameters
Type |
Name |
Description |
Vector2 |
velocity |
|
SetVerticalVelocity(Single)
Declaration
public virtual void SetVerticalVelocity(float verticalVelocity)
Parameters
Type |
Name |
Description |
System.Single |
verticalVelocity |
|
SideCollisionChecks()
Declaration
protected virtual void SideCollisionChecks()
UnfreezeController()
Declaration
public void UnfreezeController()
UpdatePhysics(MovementProperties, PhysicsVolumeType)
Declaration
public virtual void UpdatePhysics(MovementProperties movementProperties, PhysicsVolumeType volumeType = null)
Parameters
Type |
Name |
Description |
MovementProperties |
movementProperties |
|
PhysicsVolumeType |
volumeType |
|