-
Notifications
You must be signed in to change notification settings - Fork 8
ready()
This part is simple. All that “ready()” does is initialize variables and states, just in case there is a situation to where the player starts out in the level needing these variables. They may be unnecessary as most of these variables are set before they are used inside their respective function, but it makes me feel better to initialize them, anyway, as they take almost no time to do so. And you never know, someone may change the code so as to make them needed.
The first lines:
set_process_input(true)
set_physics_process(true)
These just activate the input and physics processes.
move_and_slide(
Vector3(0.0, 0.0, 0.0) ,
FloorNormal ,
SlopeStopMinVel ,
MaxSlides ,
MaxFloorAngleRad
)
Then we “move” the player. Notice the player doesn’t move anywhere. This is because the functions that check if the player is on the floor, ceiling, or wall are only updated when “move_and_slide()” is used. So that’s what we are doing here.
State_OnFloor = is_on_floor()
State_OnWalls = is_on_wall()
State_OnCeiling = is_on_ceiling()
After that set the collision states.
State_Falling = true
Then we set the player’s falling state to true, so that he starts falling when the level is started.
if(not Input.is_action_pressed(String_Jump)):
Jump_Released = true
This says whether or not the player is pressing the jump button. If he is, then he can’t jump until he releases it and then presses it again. This is just a safeguard and not that important.
Player_Position = translation
This sets the initial position of the player’s position variable.
Player_GlobalFeetPos_Y = Player_Position.y - Player_Height * 0.5
Then we get the global vertical position of the player’s feet.
if(Step_MaxHeight > Player_Height * 0.5):
Step_MaxHeight = Player_Height * 0.5
Then we check if the maximum step height is to high (above the halfway point of the player). If it is then we set it down to be half of the player’s height.
Debug_Label.set_text(Debug_Label_String)
Then we set the initial debug label text.
Touch_ObjectsTouched.resize(MaxSlides)
And then we resize the “touched objects” array.