Class PhysicController2D
Base class for custom Physics Controllers in a 2D simulation.
Inherit from this to create a custom velocity and physics interaction solution for any type of game object.
Inheritance
System.Object
PhysicController2D
Assembly: cs.temp.dll.dll
Syntax
public abstract class PhysicController2D : MonoBehaviour, IForceReceiver
Fields
_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
CurrentPhysics
Declaration
public MovementProperties CurrentPhysics
Field Value
DefaultPhysics
Declaration
public MovementProperties DefaultPhysics
Field Value
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
ReferenceSpeed
Reference speed if used for passing in a value in horizontal calculating based on running or not.
Declaration
public float ReferenceSpeed
Field Value
| Type |
Description |
| System.Single |
|
Properties
CurrentVelocity
Declaration
public Vector2 CurrentVelocity { get; }
Property Value
Direction
The property for which direction the Controller is having external input tell it to move.
Either sent via an input system for player controlled objects or a state machine for AI controlled objects.
Declaration
public Vector2 Direction { get; set; }
Property Value
Methods
AddHorizontalVelocity(Single)
Declaration
public void AddHorizontalVelocity(float horizontalVelocity)
Parameters
| Type |
Name |
Description |
| System.Single |
horizontalVelocity |
|
AddVelocity(Vector2)
Declaration
public void AddVelocity(Vector2 velocity)
Parameters
| Type |
Name |
Description |
| Vector2 |
velocity |
|
AddVerticalVelocity(Single)
Declaration
public void AddVerticalVelocity(float verticalVelocity)
Parameters
| Type |
Name |
Description |
| System.Single |
verticalVelocity |
|
CalculateHorizontal()
Declaration
protected abstract void CalculateHorizontal()
CalculateMovementState()
Declaration
protected abstract void CalculateMovementState()
CalculateVertical()
Declaration
protected abstract void CalculateVertical()
FixedUpdate()
Declaration
protected virtual void FixedUpdate()
FreezeController()
Declaration
public virtual void FreezeController()
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
Move()
Declaration
protected abstract 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()
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 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 void SetHorizontalVelocity(float horizontalVelocity)
Parameters
| Type |
Name |
Description |
| System.Single |
horizontalVelocity |
|
SetVelocity(Vector2)
Declaration
public void SetVelocity(Vector2 velocity)
Parameters
| Type |
Name |
Description |
| Vector2 |
velocity |
|
SetVerticalVelocity(Single)
Declaration
public void SetVerticalVelocity(float verticalVelocity)
Parameters
| Type |
Name |
Description |
| System.Single |
verticalVelocity |
|
UnfreezeController()
Declaration
public virtual void UnfreezeController()
Implements