Skip to content

Global Variables In Depth

James Russell edited this page Apr 9, 2018 · 3 revisions

This section explains, in detail, what each variable does at the top of the file, and where they are used. It also shows the default values of each one. The reason for these global variables is I don’t think it’s optimal to keep creating and freeing variables inside code. Let’s say the following code is inside “_physics_process()”:

var SomeVar = self.translation.y

If this variable is used over and over again each frame, I like to just create it at the top of the file once and always have it. I’m not sure if the variable is freed from memory after a single loop of “_physics_process()” or after the script is dereferenced, but it makes me feel better.

Explanation (at the Top of the Script)

This explains what the script is and references this manual as well as the wiki on the GitHub project page, which is just a copy of this manual. It also shows the URL of this project’s GitHub page:

https://github.com/leiget/Godot_FPC_Base

Notes

Says how the script must be used for correct functionality. They are:

  • The collision safety margin must be set to around 0.01 for the player's kinematic body, or else things like walking up steps and such will not work correctly.
    • You'll need to test it and find out what works whenever you change the size of the player's collision shape.
  • This script is made with the intent that the player's collision shape is a capsule.
    • If you use something else, you will need to change the code.
    • Also, a capsule shape is best because if you where to use a cube and tried to turn the character while in a confined space, the corners of the cube would go inside the objects that are confining you.
  • Note that in Godot 3.0.2 the “move_and_slide()” function has 5 arguments, but in the latest GitHub version (as of March 07, 2018) it has 6, with the added argument being in the 3rd position and is “bool infinite_inertia=true”. If this option is true, what it means is that no other object can rotate the character. If false, it can if enough force is applied.
    • bool infinite_inertia=true” means that the character can’t be rotated, because the amount of inertia needed to do so is infinite.
    • Look up “Infinite Inertia Tensor” on the net or in a book, if you want. It’s not explained in this document.

Extends

  • extends KinematicBody This extends the current script’s functionality to include the named class type and all its ancestors. For instance, the “KinematicBody” inheritance tree looks like this:
KinematicBody < PhysicsBody < CollisionObject < Spatial < Node < Object

As you can see, “KinematicBody” inherits all these classes. But what does that mean? It means you can use all these other classes’ functions. For instance, the “Spatial” class has the funtion “get_global_transform()”, which gets the global transform matrix of the current node. When you type “extend KinematicBody”, it extends the “KinematicBody” functionality to include all the inherited ancestors, and in my example you can therefore use “get_global_transform()”, even though “KinematicBody” itself doesn’t have that function.

Settings

This is the big part that has all the variables that can be changed, whether on-the-fly or before running the script, to fit the needs of the project. It’s organized into several parts according to their use. Here is a breakdown, including default values:

Mouse Look

  • MouseLook = true
    • This allows you to turn mouse look on or off, for whatever reason you need to.
    • Used in the “_unhandled_input()” function.
  • Cam_RotateSens = 0.3
    • The sensitivity of the mouse movement applied to the character’s rotation.
    • Used in the “_unhandled_input()” function.

Global Variables

  • Player_Height = 1.8
    • The total height of the player.
    • Used in several places that will be explained in their appropriate sections.

Movement

  • BaseWalkVelocity = 10
    • The walk velocity of the character, in m/s, when a movement action is pressed.
    • Used in:
      • The “SETTINGS” section to calculate “Step_SafetyMargin”.
      • The “MOVEMENT” section in the top of file to calculate the initial ”FinalWalkVelocity”.
      • The “_physics_process > INPUT > SPEED SHIFT” to calculate “FinalWalkVelocity” when the “Pressed_Shift” action is pressed or when it isn’t.
  • ShiftWalkVelocity_Multiplier = 2
    • The amount to multiply the “BaseWalkVelocity” when the “Player_Shift” action is held, to make the character move faster.
    • Used in:
      • _physics_process > INPUT > SPEED SHIFT” to calculate “FinalWalkVelocity” when the “Pressed_Shift” action is pressed.
  • MaxFloorAngleRad = 0.7
    • This is the max floor angle the character is able to walk on without it being considered a wall.
    • Used in:
      • MaxFloorAngleNor_Y” : See explanation below.
      • move_and_slide()” in the “_physics_process() > FINAL MOVEMENT APPLICATION > LINEAR MOVEMENT” section.
  • FloorNormal = Vector3(0,1,0)
    • The 3D vector which defines which was is “up”, relative to the player.
    • Used in:
      • _ready() > move_and_slide()” to initialize the state of the character.
      • _physics_process() > FINAL MOVEMENT APPLICATION > LINEAR MOVEMENT > move_and_slide()” to move the character.
  • MaxSlides = 4
    • This is the maximum number of slides to be calculated when the character is moved using “move_and_slide()”.
    • Used in:
      • Touch_CheckAndExecure()” : To set the size of the “SlideCollisions” array.
      • _ready()” : To set the size of the “Touch_ObjectsTouched” array.
      • move_and_slide()” in the “_physics_process() > FINAL MOVEMENT APPLICATION > LINEAR MOVEMENT” section.
  • SlopeStopMinVel = 0.05
    • The maximum horizontal velocity the character can have on a slope and remain still.
    • That is, when a character is on a slope, and the slope isn’t very steep, the engine will check to see how far the character would move if gravity is applied, and thus slide down the slope. If the character were to only have a velocity of, say, 0.02 while on the slope and gravity is applied, then the engine will not move the character.
    • If the body is standing on a slope and the horizontal speed (relative to the floor’s speed) goes below “SlopeStopMinVel”, the body will stop completely.
    • However, this doesn’t seem to work. I’ve tried very high values and the character would still slide on slopes. This may change in the future (written on March 07, 2018).
    • Used in “move_and_slide()” in the “_physics_process > FINAL MOVEMENT APPLICATION > LINEAR MOVEMENT” section.

Falling

  • Falling_Gravity = 9.8
    • The gravity to be used on the character.
    • It is converted to a negative number later, when needed.
    • Used in:
      • The “_physics_process() > VERTICAL MOVEMENT > JUMPING” section:
        • To check if the player’s jumping velocity is above the gravity velocity before attempting a jump.
        • To subtract it from the jump velocity when the jump action is pressed.
          • That is, “Falling_Gravity” is subtracted from the jump’s velocity so the character’s jumping velocity is affected by gravity.
  • Falling_Speed_Multiplier_Default = 0.25
    • The default value of the above variable.
    • 0.25 is a good starting place for this character script, making the final gravity when standing on a floor or slope 2.45 m/s. As stated above, a gravity of 2.45 m/s keeps the player from being pulled down too hard when on slopes, causing him to slide down it.
    • Used in:
      • Slope_AffectSpeed()”, at the end, to be the “from” argument in the “(lerp())[https://github.com/leiget/Godot_FPC_Base/wiki/lerp()]” (linearly interpolate) function so that the falling speed of the character when on the floor is never below “Falling_Speed_Multiplier_Default”.
  • Falling_TerminalVel = 54
    • The terminal velocity of the character is set here, in m/s
    • For Earth in average conditions, this is about 54 m/s.
    • Used in the “_physics_process() > VERTICAL MOVEMENT > FALLING” section to see if the player is falling at terminal velocity and to keep him from going past it.
  • Falling_TimeToHitTerminalVelSec = 14
    • The time it takes the character to hit terminal velocity, in seconds.
    • For Earth in average conditions, this is about 14 seconds.
    • Used in the “_physics_process() > VERTICAL MOVEMENT > FALLING” section to set how fast the player hits terminal velocity.

Jumping

  • Jump_Vel_RelativeToGrav = 1.55
    • The jump velocity relative to gravity.
      • This means if the force gravity is 9.8, the initial vertical velocity of the character will be “15.19” when the jump button is pressed.
    • Used in “_physics_process() > VERTICAL MOVEMENT > JUMPING” section at top of script to calculate “Jump_Vel”.
  • Jump_Length = 0.75
    • How long the jump will last until the character starts falling, in seconds.
    • Used in the “_physics_process() > VERTICAL MOVEMENT > JUMPING” section:
      • To calculate if the jump has finished.
      • To calculate the jump velocity as time passes, so as to smoothly taper off the jump as it reaches its peak.

Stepping Up

  • Step_MaxHeight = 0.5
    • The maximum height, in meters, that the player can step up a platform.
    • This must be less than half the size of the player.
      • This is because when stepping on a step, a ray cast is shot down upon the collision position to see if there is anything in the way of the player stepping up the step. If this height is more than half the height of the character, it will be set to half the height of the character. This happens in the "_ready()" function.
    • Used in:
      • The “Step_Player_Up()” function to set the vertical position of the step raycast.
      • _ready()” to check if “Step_MaxHeight” is more than half the players height and set it to that.
  • Step_SafetyMargin_Dividend = 0.02
    • The dividend for the step safety margin variable, below.
    • Used in:
      • Step_SafetyMargin” variable right below this one.
      • "_physics_process() > INPUT > SPEED SHIFT" to alter the step safety margin based on the speed of the character.
  • Step_RaycastDistMultiplier = 1.1
    • The amount to move the ray cast away from the player to help detect steps more accurately.
    • When the character hits a potential step, a ray is cast from above that position, level to the player’s global origin. It shoots straight down, level to where the player’s “feet” are, checking for a collision.
      • This variable is the multiplied distance from the player the ray should be cast. This is to ensure that the ray cast origin is completely over the step, and also to ensure tiny steps are ignored.
    • Used in the “Step_Player_Up()” function.

Camera Interpolation

  • CamInterpo_Length_Secs_Multiplicand = 125.0
    • The multiplicand for the "CamInterpo_Length_Secs" variable below.
    • Lower this number to make the camera interpolation speed slower.
    • Used in:
      • CamInterpo_Length_Secs” variable, below.
      • The “_physics_process() > INPUT > SPEED SHIFT” section to alter the speed of the camera interpolation based on the player’s speed.

Slope Speed

  • Slope_EffectMultiplier_ClimbingUp = 0.3
    • The multiplier that sets how much a slope affects the character’s applied gravity when climbing up one.
    • Used in “Slope_AffectSpeed()” to say how much slopes affect walking speed when moving up one.
  • Slope_EffectMultiplier_ClimbingDown = 1.5
    • The multiplier that sets how much a slope affects the character’s applied gravity when climbing up one.
      • This is more than 1.0 because I want the player to “stick” to the slope when walking down it, so as to keep the character from raising off the platform and falling on it, over and over again.
      • It also gives a sense of gravity as a person tends to walk down slopes faster than up them.
    • Used in “Slope_AffectSpeed()” to say how much slopes affect walking speed when moving down one.

Use Action

  • Ray_UseDist = 2.0
    • The distance (in meters) the use button ray can go; the ray that looks for things that can be used.
    • Used in “_physics_process > INPUT > CROSSHAIR: USABLE ITEM AND USE BUTTON” section.

Signals

See the respective sections for in-depth explanations of each signal and how to use them.

  • Render_Pos(Coll_Vec3)
    • Signal for rendering any 3D position.
    • Arguments:
      • Coll_Vec3
        • Type: Vector3
        • Description: The 3D position that you want to represent.
    • Not used in the default script.
      • You can put this wherever you want to represent any position.
  • Coll_Sphere_Show(SlideNumber, Pos_Vec3)
    • Signal for showing collision slides from "move_and_slide()".
    • Arguments:
      • SlideNumber
        • Type: int
        • Description: The slide number you want to represent.
      • Pos_Vec3
        • Type: Vector3
        • Description: The position of the slide number to be represented.
    • Not used in the default script.
    • Can be put anywhere a “for Slide in range(SlideCount):” exist.

Nodes

These are simply node pointers to make accessing them easier.

  • Node_Camera3D = get_node("Camera_Main")
    • Simply the player’s 3D camera node representing the player’s vision.
    • Used in:
      • The “CAMERA STEP SMOOTHING” section at the top of the file to get the default local position of the camera.
      • In the “InterpolateCamera()” function to move the camera.
      • In the “Step_Player_Up()” function to get the global position of the camera before being moved up the step and to move it there after the whole player is moved up the step.
      • In “_input()” to get and set the vertical rotation of the camera.
      • In the “_physics_process > INPUT > CROSSHAIR: USABLE ITEM AND USE BUTTON” section to see if the player is pointing at anything within range that can be used.
  • Node_Crosshair_Useable = get_node("Camera2D/Crosshair/Crosshair_Useable")
    • The red circle that shows up when the player is within reach of and looking at a usable object.
    • Used in the “_physics_process > INPUT > CROSSHAIR: USABLE ITEM AND USE BUTTON” section to show and hide itself.
  • Debug_Label = get_node("Camera2D/DEBUG/Debug_Label")
    • The debug label in the player’s tree that shows whatever the programmer wants it to show.
    • Used only once at the end of the script.
  • Debug_Label_String = "-------------------"
    • The string to be printed in the debug label. Simply make the string whatever you want to be shown on the screen.
    • Example: “Debug_Label_String = “Player Position = ” + str(Player_Position)
    • Used, by default, at the end of the script to show the FPS.

States

These are state variables, that is bools that say whether a certain condition exist or not. These are here for convenience and for only accessing the GDscript’s state getting function once. That is, “is_on_floor()” is only needed to be called after a “move_and_slide()” once using “State_OnFloor = is_on_floor()" instead of calling “is_on_floor()” every time you need to check if the player is on the floor.

  • State_OnFloor = false
  • State_OnWalls = false
  • State_OnCeiling = false
    • Says whether the player character is hitting a wall, floor, or ceiling.
    • Used in several places that will be explained in-depth in their appropriate sections.
  • State_Falling = false
    • Says if the player is falling.
    • Used in several places that will be explained in-depth in their appropriate sections.
  • State_Jumping = false
    • Says if the player is in the middle of a jump.
    • After the player has reached his jump peak, this variable becomes “false” and the player starts falling.
    • Used in several places that will be explained in-depth in their appropriate sections.
  • State_Movement_Diagonal_Pressed = false
    • Says if the player is pressing a forward/backward and left/right key at the same time.
    • Used in several places that will be explained in-depth in their appropriate sections.

Global Variables

These are simply variables that are used in several different sections of the code, instead of being used only in one section. Or they may be here as there is no other section that it could go.

  • Player_Position = Vector3(0,0,0)
    • The global position of the player character’s origin.
    • Used in several places that will be explained in-depth in their appropriate sections.
  • Player_GlobalFeetPos_Y = Player_Position.y - Player_Height/2
    • The global position of the very bottom part of the player character’s collision shape.
    • Simply called “feet position” for simplicity.
    • Used in:
      • The “Step_Player_Up()” function to set and get the position of the bottom of the player’s collision shape.
      • _ready()”; it’s initialized here.

Input

Input bools and action strings (the ones that are set in the “Project Settings/Input Map” tab, at the top).

  • Pressed_FW = false
  • Pressed_BW = false
  • Pressed_LEFT = false
  • Pressed_RIGHT = false
  • Pressed_Jump = false
  • Pressed_Shift = false
    • The bools that say if a action is pressed/active.
    • Used in:
      • _physics_process() > INPUT > MOVEMENT” to receive the action states.
      • _physics_process() > HORIZONTAL MOVEMENT” to calculate movement velocity.
  • String_FW = "Player_FW"
  • String_BW = "Player_BW"
  • String_Left = "Player_Left"
  • String_Right = "Player_Right"
  • String_Jump = “Player_Jump”
  • String_Use = “Player_Use”
  • String_Shift = “Player_Shift”
    • The strings that are the names of the actions in the project settings.
    • I.e: “ui_up” or “Player_FW”.
    • Used in:
      • _physics_process() > INPUT > MOVEMENT” to get action states according to name.

Movement

Variables concerning the horizontal movement of the player lay here.

  • MaxFloorAngleNor_Y = cos(MaxFloorAngleRad)
    • This is the max floor angle, but converted to what it is as a normal, so that the floor normal can be compared to this without having to constantly convert it to radians.
    • Used in:
      • Step_Player_Up()
        • To see if a slide collision is a wall.
        • To see if the result from the raycast downward is a floor.
      • Slope_AffectSpeed()” : To compare the current slide normal to the maximum, to get a ratio of how slow the character should move relative to the “BaseWalkVelocity”.
      • In the “_physics_process > VERTICAL MOVEMENT > FALLING” section to see if a current slide collision is a floor or not.
  • SlideCount = 0
    • This holds the slide count. Filled with whatever “get_slide_count()” returns.
    • Used so “get_slide_count()” doesn’t have to be called over and over.
    • Used in several places that will be explained in-depth in their appropriate sections.
  • DirectionInNormalVec3_FWAndBW = Vector3(0,0,0)
  • DirectionInNormalVec3_LeftAndRight = Vector3(0,0,0)
    • The 3D vectors that say which way the player is facing in normalized vectors.
    • See the “Normals Explained” section.
    • Used in:
      • “_physics_process() > GET ROTATION-DIRECTION NORMALS” to get the direction the player is facing in normals.
      • “_physics_process() > HORIZONTAL MOVEMENT > FORWARD AND BACKWARDS CALCULATIONS” to set the direction the player should move.
  • TempMoveVel_FWAndBW = Vector3(0,0,0)
  • TempMoveVel_LeftAndRight = Vector3(0,0,0)
    • The calculated horizontal movement velocity of the character before being added together to form “FinalMoveVel”.
    • Used in:
      • _physics_process() > HORIZONTAL MOVEMENT” to receive the temporary velocity of the player in the variables receptive direction. That is, “TempMoveVel_FWAndBW” holds the velocity of the player only in the forward and backwards direction, and will be added to “TempMoveVel_LeftAndRight” in the “_physics_process() > HORIZONTAL MOVEMENT > ADD X AND Z AXIS” section .
      • Slope_AffectSpeed()” to find out if the player is moving up, down, or perpendicular to the slopes normal.
  • FinalWalkVelocity = BaseWalkVelocity
    • The final walk velocity applied to the horizontal movement of the player.
    • This is used because when the “Player_Shift” action isn’t pressed, the walk velocity needs to be “BaseWalkVelocity”, that is, the player needs to move at his normal speed. But if the “Player_Shift” action is pressed, the speed of the player needs to be “BaseWalkVelocity * ShiftWalkVelocity_Multiplier”.
    • This changed on-the-fly to cause effects such as walking slower through water or swamps, if need be.
    • Used in several places that will be explained in-depth in their appropriate sections.
  • FinalMoveVel = Vector3(0,0,0)
    • The final velocity to be applied to the player in “move_and_slide()” in the “_physics_process() > FINAL MOVEMENT APPLICATION > LINEAR MOVEMENT” section.
    • Used in several places that will be explained in-depth in their appropriate sections.

Rotation

For rotating the player and his camera.

  • Mouse_Moved = false
    • The bool that says to rotate the character because the mouse has been moved.
  • Mouse_Rel_Movement = Vector2(0, 0)
    • The amount of pixels the mouse has been moved in the last frame.
    • Used in “_input()” to rotate the character.
  • Cam_Local_Rot_X = 0
    • The camera’s local rotation on its X-axis, which is up and down.
    • Used in “_input()” to rotate the character.
  • Final_Cam_Rot_Local_X = 0
    • The amount to be applied to the camera’s local X-axis.
    • Used in “_input()” to rotate the character.
  • Cam_Temp_XRot_Var = 0
    • The amount the camera has moved, vertically, before being limited.
    • That is, if the player is looking straight up, and then moves his mouse up even farther, this variable will hold the angle that the camera would be before being limited to 90° up or down.
    • Used in “_input()” to rotate the character.

Falling

Variables used when the player is falling.

Note: The player is technically considered to be “falling” when standing still on a floor. The “Falling_Speed_Multiplier” is set to “Falling_Speed_Multiplier_Default” when standing still on a floor. By default, that would mean that “Falling_Speed_Multiplier = 0.25”, and that “FinalMoveVel.y = -2.45”, if “Falling_Gravity = 9.8”. This is so because if the vertical velocity is -9.8 when standing on a slope, the character will slide down it because of the force of gravity.

  • Falling_IsFalling = false
    • States if the player is falling.
    • Used in several places that will be explained in-depth in their appropriate sections.
  • Falling_Speed = 0
    • The falling speed that is actually used to move the player.
    • Used in several places that will be explained in-depth in their appropriate sections.
      • Notably, it is used in the “_physics_process() > VERTICAL MOVEMENT > FALLING” section to calculate how fast the player is currently falling, in relation to how long he has been falling.
  • Falling_Speed_Multiplier = 0.0
    • The multiplier to modify the falling speed of the character.
    • This is used when the character is moving on a slope to affect movement speed.
    • This is also used when the character is standing on the slope. When the character is on one, it is set to “Falling_Speed_Multiplier_Default” to keep the character from sliding down it because gravity is pulling him down too hard.
    • Used in:
      • Slope_AffectSpeed()”, at the end, to modify how fast or slow the character moves on an incline.
      • The “_physics_process() > VERTICAL MOVEMENT > FALLING” section to set the falling speed of the player to the default.
        • That is it sets “Falling_Speed_Multiplier” to “Falling_Speed_Multiplier_Default” when just standing still on a floor.
  • Falling_CurrentTime = 0
    • The amount of time, in seconds, the player has been falling.
    • Used to calculate the vertical velocity.
    • Used in several places that will be explained in-depth in their appropriate sections.

Jumping

Variables for when the player is jumping.

  • Jump_Vel = Falling_Gravity * Jump_Vel_RelativeToGrav
    • This value is the initial value of “Jump_CurrentVel” after the jump button is pressed.
    • Used in the “_physics_process() > VERTICAL MOVEMENT > JUMPING” section for several things. Will be detailed in the appropriate section of this manual.
  • Jump_CurrentVel = 0.0
    • The current velocity of the jump, which is fed into “FinalMoveVel”.
    • This tapers off, over the length of the jump, until the peak of the jump has been reached. When that happens, the player is no longer considered to be jumping (“State_Jumping=false”), and the player starts falling (“State_Falling=true”).
    • Used in:
      • The “_physics_process() > VERTICAL MOVEMENT > ON FLOOR” to set the jump velocity to “0” after landing from a jump.
      • The “_physics_process() > VERTICAL MOVEMENT > JUMPING” section for several things. Will be detailed in the appropriate section of this manual.
  • Jump_CurrentTime = 0.0
    • The current time of the jump, in seconds.
    • This is relative to when the jump started.
    • Used in:
      • The “_physics_process() > VERTICAL MOVEMENT > JUMP PRESSED” section to set the current time of the jump to “0” when the jump key is pressed.
      • The “_physics_process() > VERTICAL MOVEMENT > JUMPING” section to check if the jump is over, to calculate the jump velocity, and to progress the jump time according to the “_physics_process()” delta.
  • Jump_Released = true
    • This says whether the jump action has been released or not.
    • I could of used “is_action_just_pressed(String_Jump)” to just get the start of the player’s pressing the jump action, but I only figured that out after I was done programming the jumping.
      • So I left this here in case someone wants to implement dynamic jumping, to where the player can alter the length of the jump by holding down the jump key longer.
    • Used in several places to see that will be explained in the appropriate section.

Slope Speed

Variables concerning the slowing down or speeding up of the player while on an incline.

  • Slope_PlayerVelVec2D = Vector2(0.0, 0.0)
    • The player horizontal velocity.
    • Used in:
      • Step_Player_Up()” to find out if the player is more than 11.5 degrees perpendicular to the step before attempting to move him up it. Explained in the “Step_Player_Up()” section.
      • Slope_AffectSpeed()” to compare it to the slopes normal to see if the character is moving up, down, or sideways on a slope.
  • Slope_FloorNor2D = Vector2(0.0, 0.0)
    • The floor’s normal on the horizontal normals.
    • To be compared to the player’s horizontal velocity.
    • Used in “Slope_AffectSpeed()” to be compared against the players normal, above, to see if the character is moving up, down, or sideways on a slope. Explained in the appropriate section.
  • Slope_DotProduct = 0.0
    • The dot product of the player’s horizontal velocity against the slope’s horizontal normal.
    • Used in “Slope_AffectSpeed()” to see if the character is moving up, down, or sideways on a slope and to calculate his velocity appropriately.

Steps

Variables concerning the stepping up of the player upon steps and raised platforms.

  • Step_SafetyMargin = Step_SafetyMargin_Dividend/BaseWalkVelocity
    • The additional amount that character has to move up when stepping up a step.
    • This helps keep the character from getting stuck when moving up and down steps/platforms because he can't get quite enough height to get over the step, and therefore slides back down off the edge of it.
    • It's set according to how fast the player is moving, so that the stepping of stairs is more correct.
    • Used in:
      • Step_Player_Up()”; to add to the “SteppingUp_SteppingDistance” to make sure the player goes up far enough to get fully on the step.
      • The “_physics_process > INPUT > SPEED SHIFT” section to to set “Step_SafetyMargin” according to how fast the player character is moving.
  • SteppingUp_SteppingDistance = 0.0
    • The variable that says how high to move the character up to be able to get on the step.
    • Used in “Step_Player_Up()” to say how far to move the player up a step and how far down to locally move the camera down after moving the whole player character up.
  • Step_CollPos = Vector3(0.0, 0.0, 0.0)
    • The global position of the collision of the player against a wall.
    • This is not the ray cast collision position. It is the collision detection’s slide collision of the player character’s kinematic body.
    • Used in “Step_Player_Up()” to cast rays towards and upon the step.
  • Step_CollPos_RelToPlayer = Vector3(0.0, 0.0, 0.0)
    • The position of the collision of the step/wall relative to the player.
    • Used in “Step_Player_Up()” to move the ray cast away from the player a little to make sure it actually hits the step and doesn’t miss it by a little bit.
  • Step_Cam_PosBefore_Global = 0.0
    • The global position of the player’s camera before he was moved up a step.
    • This is used for camera interpolation.
    • I put it here because it is modified in the "Step_Player_Up()" function.
    • Used in “Step_Player_Up()” to set the global position of the player’s camera before moving up the step.

These variables, below, are used for keeping the player from trying to move up a step if he is too parallel to it, causing him to step up and slide back down repeatedly because he is not able to fully get on the step, but only on the edge. Check the “Step_Player_Up()” section for more information.

  • Step_PlayerVel_Global_Norm = Vector3(0,0,0)
    • The global velocity of the player, normalized.
    • Basically, it just says what direction the player is moving (not the direction he is facing).
    • Used in “Step_Player_Up()” to find the angle between the step’s normal and the player’s velocity.
  • Step_CollPos_Global_RelToPlayer = Vector3(0,0,0)
    • The step’s collision position, relative to the player, but in global space.
    • Used to find the angle between the player’s velocity and the step to see if they are perpendicular enough to allow stepping.
    • Used in “Step_Player_Up()” to find the angle between the step’s normal and the player’s velocity.
  • Step_CollPos_AngleToPlayer = 0.0
    • The final angle of the player against the step collision.
    • Used in “Step_Player_Up()” to keep the player from trying to walk up a step that he’s walking too parallel to.

Camera Step Smoothing

Variables concerning the smoothing (interpolation) of the camera when the player walks up steps on moves up on a platform.

  • CamInterpo_Length_Secs = BaseWalkVelocity / (CamInterpo_Length_Secs_Multiplicand * (BaseWalkVelocity/10.0))
    • How long it takes to interpolate the camera, in seconds.
    • Dependant on speed of character.
    • The default length is 0.08 seconds, if BaseWalkVelocity is 10.
    • Used in:
      • InterpolateCamera()” to see if the camera interpolation is over and to calculate how far the interpolation is, at the current frame.
      • The “_physics_process() > INPUT > SPEED SHIFT” section to calculate how long the camera interpolation should be when the player is pressing the shift key, or when he’s not.
  • CamInterpo_DoInterpolation = false
    • Tells script whether or not to do camera interpolation.
    • Initialized in the “Step_Player_Up()” function.
    • Used in:
      • InterpolateCamera()” to turn off interpolation after it is done.
      • Step_Player_Up()” to turn on interpolation after a step.
      • The “_physics_process() > FINAL MOVEMENT APPLICATION > CAMERA INTERPOLATION” section to check if camera interpolation should be done.
  • onready var CamInterpo_DefaultPosition_Local_Y = Node_Camera3D.get_transform().origin.y
    • The default local position of the camera.
    • This value is basically whatever the camera’s location is inside the “player.tscn” scene. It’s relative to the player’s origin.
    • This is what the camera will interpolate to when stepping up. To change this, simply change the vertical position of the player’s camera inside “player.tscn”.
    • Used in “InterpolateCamera()” to be the location to which it will be interpolated.
  • CamInterpo_StartingPos_Local_Y = 0.0
    • The camera position, in local space, where it would be if it had not moved up with the player when encountering a step.
    • Used in:
      • Step_Player_Up()” to set itself according to where it would be if it had not moved up with the player when encountering a step.
      • The “_physics_process() > FINAL MOVEMENT APPLICATION > CAMERA INTERPOLATION” as the first argument in the “InterpolateCamera()” function.
  • CamInterpo_CurrentTime_Secs = 0.0
    • The current time of the camera interpolation that is in progress, in seconds.
    • Used in:
      • Step_Player_Up()” to set the time of the interpolation to “0” after the player has gone up a step.
      • The “_physics_process() > FINAL MOVEMENT APPLICATION > CAMERA INTERPOLATION” section as the keeper of the return value of “InterpolateCamera()” and also as its second argument.

Ray Casting

Variables concerning the casting of rays.

  • Ray_SpaceState = null
    • The state of the physical space in the game.
    • This holds all the information about collisions, collision boxes, where they are located, how big they are, their shape, and anything else pertaining to collision detection.
    • Used in several places.
  • Ray_From = Vector3(0.0, 0.0 ,0.0)
    • The position that the ray cast will come from.
    • Used in several places.
  • Ray_To = Vector3(0.0, 0.0 ,0.0)
    • The position that the ray cast will go to.
    • Used in several places.
  • Ray_Result = null
    • The resulting dictionary of information received from “Ray_SpaceState.intersect_ray()”, which holds information like the collider, the ray cast collision position, or if the ray cast even hit anything in the first place.
    • Used in several places.

Interaction

Variables concerning interaction via touch and the “Use” action.

  • Use_Ray_IntersectPos = Vector3(0,0,0)
    • The “Use” action’s ray cast collision (aka intersection) position.
    • Used in:
      • The “_physics_process() > INPUT > CROSSHAIR: USABLE ITEM AND USE BUTTON” section to set the position of the ray intersection.
      • In “Sphere.gd” to set the position of the applied impulse.
  • Touch_ObjectsTouched = []
    • The list of objects that have been touched and that also contain a “Touched_Function()” method (another word for function).
    • Used in:
      • Touch_CheckAndExecute()” to keep track to objects that have been touched that have a “Touched_Function()” function.
      • _ready()” to set its size.
  • SlideCollisions = []
    • The list of slide collisions to be compared against the “Touch_ObjectsTouched[]” array.
    • Used in “Touch_CheckAndExecute()” to keep track of the frame’s current slide collisions.
Clone this wiki locally