Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- Player
- PlayerModelManager
- PlayerPickUpObjectEvent
- PlayerSetFarmAnswerEvent
- PlayerSetFarmEvent
- PlayerSetHandToolEvent
- PlayerStateActivateObject
- PlayerStateAnimalFeed
- PlayerStateAnimalInteract
- PlayerStateAnimalPet
- PlayerStateAnimalRide
- PlayerStateBase
- PlayerStateCrouch
- PlayerStateCycleHandtool
- PlayerStateDrop
- PlayerStateFall
- PlayerStateIdle
- PlayerStateJump
- PlayerStateMachine
- PlayerStatePickup
- PlayerStateRun
- PlayerStateSwim
- PlayerStateThrow
- PlayerStateUseLight
- PlayerStateWalk
- PlayerStyle
- PlayerSwitchedFarmEvent
- PlayerTeleportEvent
- PlayerThrowObjectEvent
- PlayerToggleLightEvent
- Shop
- Sounds
- Specializations
- Triggers
- Utils
- Vehicles
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
PlayerStateJump
ParentPlayerStateBaseFunctions
activate
DescriptionActivate method. Set vertical velocity.Definition
activate()Code
58 | function PlayerStateJump:activate() |
59 | PlayerStateJump:superClass().activate(self) |
60 | |
61 | local velY = math.sqrt(-2.0 * self.player.motionInformation.gravity * self.player.motionInformation.jumpHeight) |
62 | local jumpFactor = 2.0 |
63 | self.player.motionInformation.currentSpeedY = velY * jumpFactor |
64 | |
65 | if self:inDebugMode() then |
66 | self.playerPos = {} |
67 | self.jumpDuration = 0.0 |
68 | end |
69 | end |
consoleCommandDebugStateJump
DescriptionConsole command to debug draw the jump stateDefinition
consoleCommandDebugStateJump()Code
114 | function PlayerStateJump:consoleCommandDebugStateJump() |
115 | self:toggleDebugMode() |
116 | if self:inDebugMode() then |
117 | self.playerPos = {} |
118 | end |
119 | end |
deactivate
DescriptionDeactivate method.Definition
deactivate()Code
73 | function PlayerStateJump:deactivate() |
74 | PlayerStateJump:superClass().deactivate(self) |
75 | |
76 | self.jumpWeight = 0 |
77 | end |
debugDraw
DescriptionDebug draw method.Definition
debugDraw(float dt)Arguments
float | dt | delta time in ms |
106 | function PlayerStateJump:debugDraw(dt) |
107 | for i=1, #self.playerPos do |
108 | DebugUtil.drawDebugCircle( self.playerPos[i][1], self.playerPos[i][2], self.playerPos[i][3], 0.1, 10) |
109 | end |
110 | end |
delete
DescriptionDefinitiondelete()Code
31 | function PlayerStateJump:delete() |
32 | if self.player.isOwner then |
33 | removeConsoleCommand("gsToggleDebugStateJump") |
34 | end |
35 | end |
isAvailable
DescriptionCheck if state is available. Check that player is on the ground.Definition
isAvailable()Return Values
bool | true | if player can jump |
48 | function PlayerStateJump:isAvailable() |
49 | if self.player:hasHandtoolEquipped() and self.player.baseInformation.currentHandtool:isBeingUsed() then |
50 | return false |
51 | end |
52 | local isOnGround = self.player.baseInformation.isOnGround |
53 | return isOnGround and not g_currentMission:isInGameMessageActive() |
54 | end |
load
DescriptionLoad methodDefinition
load()Code
39 | function PlayerStateJump:load() |
40 | if self.player.isOwner then |
41 | addConsoleCommand("gsToggleDebugStateJump", "Toggle debug mode for Jump", "consoleCommandDebugStateJump", self) |
42 | end |
43 | end |
new
DescriptionCreating instance of state.Definition
new(table player, table stateMachine)Arguments
table | player | instance of player |
table | stateMachine | instance of the state machine manager |
table | instance | instance of object |
19 | function PlayerStateJump:new(player, stateMachine) |
20 | local self = PlayerStateBase:new(player, stateMachine, PlayerStateJump_mt) |
21 | |
22 | -- debug code |
23 | self.playerPos = {} |
24 | self.jumpDuration = 0.0 |
25 | |
26 | return self |
27 | end |
update
DescriptionUpdate method. If the fall player state is available, we deactive this state.Definition
update(float dt)Arguments
float | dt | delta time in ms |
82 | function PlayerStateJump:update(dt) |
83 | if self.stateMachine:isAvailable("fall") or (self.player.baseInformation.isOnGround and self.player.motionInformation.currentSpeedY <= 0.0) then |
84 | if self:inDebugMode() then |
85 | local startPos = self.playerPos[1] |
86 | local endPos = self.playerPos[#self.playerPos] |
87 | local delta = endPos[2] - startPos[2] |
88 | print(string.format("[PlayerStateJump:update] End jump / duration(%.4f s) / height(%.4f).", self.jumpDuration * 0.001, delta)) |
89 | end |
90 | self:deactivate() |
91 | end |
92 | |
93 | -- debug code |
94 | if self:inDebugMode() then |
95 | local posX, posY, posZ = getWorldTranslation(g_currentMission.player.rootNode) |
96 | local newEntry = {posX, posY, posZ} |
97 | |
98 | table.insert(self.playerPos, newEntry) |
99 | self.jumpDuration = self.jumpDuration + dt |
100 | end |
101 | end |