Skip to main content
Skip to main content

PlayerStateSwim

PlayerStateSwim

Description

The state used for the player moving or being still on foot while deep enough in water.

Parent

BaseStateMachineState

Functions

calculateDesiredHorizontalVelocity

Description

Calculates the desired horizontal velocity in metres per second.

Definition

calculateDesiredHorizontalVelocity(float directionX, float directionZ)

Arguments

floatdirectionXThe direction on the x axis to use.
floatdirectionZThe direction on the z axis to use.

Return Values

floatxThe desired x.
floatzThe desired z.

Code

function PlayerStateSwim:calculateDesiredHorizontalVelocity(directionX, directionZ)

-- Calculate the speed to use then return it as a velocity vector.
local speed = self:calculateDesiredSpeed()
return directionX * speed, directionZ * speed
end

new

Description

Creates a state with the given player and managing state machine.

Definition

new(Player player, StateMachine stateMachine)

Arguments

PlayerplayerThe player who owns this state.
StateMachinestateMachineThe state machine managing this state.

Return Values

StateMachineinstanceThe created instance.

Code

function PlayerStateSwim.new(player, stateMachine)

-- Create the instance, set the player, then return the instance.
local self = BaseStateMachineState.new(stateMachine, PlayerStateSwim _mt)
self.player = player
return self
end

updateAsCurrent

Description

Updates this state when it is currently the state machine's current state. Calls stateMachine:determineState() when calculateIfShouldBeForced() returns false.

Definition

updateAsCurrent(float dt)

Arguments

floatdtDelta time in ms.

Code

function PlayerStateSwim:updateAsCurrent(dt)
if not self:calculateIfShouldBeForced() then
self.stateMachine:determineState()
end
end