SF Tool Documentation
Search Results for

    Show / Hide Table of Contents

    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
    ControllerBody2D
    Implements
    IForceReceiver
    Namespace: SF.PhysicsLowLevel
    Assembly: cs.temp.dll.dll
    Syntax
    public abstract class PhysicController2D : MonoBehaviour, IForceReceiver
    Remarks

    The base class doesn't care or understand the difference between a or a . They inheriting classes define which one to use.

    Fields

    _calculatedVelocity

    The overall velocity to be added this frame.

    Declaration
    protected Vector2 _calculatedVelocity
    Field Value
    Type Description
    Vector2

    _direction

    Declaration
    protected Vector2 _direction
    Field Value
    Type Description
    Vector2

    _directionLastFrame

    Declaration
    protected Vector2 _directionLastFrame
    Field Value
    Type Description
    Vector2

    _externalVelocity

    Velocity adding through external physics forces such as gravity and interactable objects.

    Declaration
    protected Vector2 _externalVelocity
    Field Value
    Type Description
    Vector2

    _previousDirection

    Used to keep track of the direction to restore after unfreezing the Controller2D.

    Declaration
    protected Vector2 _previousDirection
    Field Value
    Type Description
    Vector2

    CurrentPhysics

    Declaration
    public MovementProperties CurrentPhysics
    Field Value
    Type Description
    MovementProperties

    DefaultPhysics

    Declaration
    public MovementProperties DefaultPhysics
    Field Value
    Type Description
    MovementProperties

    IsFrozen

    Declaration
    public bool IsFrozen
    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

    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
    Type Description
    Vector2

    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
    Type Description
    Vector2

    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
    public void Init()

    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

    IForceReceiver
    In This Article
    Back to top Generated by DocFX