PlayerControllerComponent

A component related to the Player control. Associates inputs with actions and controls their flow.

# Properties

[{"index":"boolean AlwaysMovingState (Sync)","0":"Determines whether to always play the walk animation."}]

[{"index":"int32 FixedLookAt (Sync)","0":"Fixes direction of view when moving."}]

[{"index":"boolean IsUpdateBlocked (ReadOnly) (HideFromInspector)","0":"Displays whether the player's input processing is currently disabled. It becomes true when the player input needs to be temporarily blocked like with map movement."}]

[{"index":"float LookDirectionX (Sync)","0":"The direction the character is facing currently based on the axis X. Right if positive, left if negative."}]

[{"index":"boolean UseCustomScript (ReadOnly)","0":"Property for using custom scripts.If true, some PlayerControllerComponent features are disabled and you can use custom scripts."}]

##### inherited from Component:

[{"index":"boolean Enable (Sync)","0":"Checks whether Component is activated or not."}]

[{"index":"boolean EnableInHierarchy (ReadOnly) (HideFromInspector)","0":"Displays whether this Component is Enable in the hierarchy. If Entity Enable is false regardless of Component Enable, returns false."}]

[{"index":"Entity Entity (ReadOnly)","0":"The Entity that owns this component."}]

# Methods

[{"index":"void ActionAttack() (ScriptOverridable)","0":"The action upon entering the Attack Key."}]

[{"index":"void ActionClimb(Vector2 moveOffset, float climbHeight) (ScriptOverridable)","0":"The action made when the MoveUp and MoveDown Keys are input. Executes the ladder or rope climbing action.Checks if there is a climbable Entity based on the set location offset and height and attempts to convert to the climb state."}]

[{"index":"boolean ActionClimb(Vector2 moveOffset, float climbHeight, float horizontalInput)","0":"Performs the action of climbing a ladder or rope.Checks if there is a climbable Entity based on the specified position offset and height, and attempts to switch to the climb state."}]

[{"index":"void ActionCrouch() (ScriptOverridable)","0":"The action upon entering the Crouch Key."}]

[{"index":"void ActionDownJump() (ScriptOverridable)","0":"The action on ActionDownJump."}]

[{"index":"boolean ActionDownJump(float horizontalInput)","0":"Executes the down jump action."}]

[{"index":"void ActionEnterPortal() (ScriptOverridable)","0":"The action upon entering the Portal Key."}]

[{"index":"void ActionInteraction(KeyboardKey key, boolean isKeyDown) (ScriptOverridable)","0":"The action upon entering the Interaction Key."}]

[{"index":"void ActionJump() (ScriptOverridable)","0":"The action upon entering the Jump Key."}]

[{"index":"boolean ActionJump(float horizontalInput)","0":"Executes the jump action."}]

[{"index":"void ActionSit() (ScriptOverridable)","0":"The action upon entering the Sit Key."}]

[{"index":"void AddCondition(string actionName, func -> boolean conditionFunction) (ClientOnly)","0":"Add conditions to trigger an action."}]

[{"index":"string GetActionName(KeyboardKey key) (ClientOnly)","0":"Returns the names of the actions mapped to the keys."}]

[{"index":"void RemoveActionKey(KeyboardKey key) (ClientOnly)","0":"Removes the actions connected to the defined keys."}]

[{"index":"void RemoveAllActionKeyByActionName(string actionName) (ClientOnly)","0":"Removes all actions connected to the defined names."}]

[{"index":"void SetActionKey(KeyboardKey key, string actionName, func -> boolean conditionFunction = nil) (ClientOnly)","0":"Map actions to the keys."}]

##### inherited from Component:

[{"index":"boolean IsClient()","0":"Returns whether the current execution environment is a client or not."}]

[{"index":"boolean IsServer()","0":"Returns whether the current execution environment is a server or not."}]

# Events

[{"index":"ChangedLookAtEvent","0":"This occurs when changing the direction for the character to face in the PlayerControllerComponent."}]

[{"index":"PlayerActionEvent","0":"This event is raised when the player uses an Action."}]

# Examples

In this example, keyboard inputs are linked to predefined actions, such as Jump, Portal, Crouch, Attack, and Sit.  
User-defined action names are linked to keyboard inputs for logging.

Tap the B key to Attack and the N key to Jump. You can also tap the G key to view user-defined action names being output to the log.
    
    
    @Component
    script PlayerInputMapper extends Component
        @ExecSpace("ClientOnly")
        method void OnBeginPlay()
        self.Entity.PlayerControllerComponent:SetActionKey(KeyboardKey.B, "Attack")
        self.Entity.PlayerControllerComponent:SetActionKey(KeyboardKey.N, "Jump")	 
        self.Entity.PlayerControllerComponent:SetActionKey(KeyboardKey.G, "MyPlayerAction")
        end
    
        @EventSender("Self")
        handler HandlePlayerActionEvent(PlayerActionEvent event)
        -- Parameters
        local ActionName = event.ActionName
        local PlayerEntity = event.PlayerEntity
        --------------------------------------------------------
        log(ActionName)
        end
    end
    

# SeeAlso

  * AvatarRendererComponent
  * StateComponent
  * StateStringToAvatarActionComponent
  * [Setting and Controlling Player](/docs?postId=547)