Skip to content

1 How to use the system

ywmaa edited this page Apr 7, 2022 · 6 revisions

GD Script Files

"CharacterMovement_Base.gd" : The Movement System is Written here, so the movement could be used in player or AI by triggering some functions

"PlayerGameplay.gd" : here it calls the functions that causes the player to move as an example for how the system should work

"Camera.gd" : handles the camera movement

"Global.gd" : Has all global variables and enums

"Interaction.gd" : attached to a raycast to do simple interaction system

"Interactable.gd" : a simple script to extend to be able to turn an object into interactable

Main Functions And its uses

"CharacterMovement_Base.gd" main functions :

add_movement_input(direction: Vector3, Speed: float , Acceleration: float)

it makes the character move and calculates all the stuff like : input_velocity, actual_velocity, input_is_moving, is_moving, input_acceleration, actual_acceleration,

jump() obvious, it makes the character jump :)

ik_look_at(position: Vector3) makes the character look at a target

Variables And its uses

Info Variables :

(They are made to get info not change them as they will already change according to the movement)

when a variable starts with the word "Input" it means its value is the amount that the character should move and not the actual value that is based on the real movement and speed, for example the Player Pressed Move Forward but the character is stopped by a wall

the value input_velocity.length() will = 1.0 while the value actual_velocity.length() will = 0.0

var actual_acceleration :Vector3 var input_acceleration :Vector3

var vertical_velocity := 0.0

var input_velocity : Vector3 var actual_velocity : Vector3

var is_moving := false var input_is_moving := false

var head_bonked := false

var aim_rate_h :float

var deacceleration := 10.0

var current_movement_data = {

        walk_speed = 1.75,
	run_speed = 3.75,
	sprint_speed = 6.5,

	walk_acceleration = 20.0,
	run_acceleration = 20.0,
	sprint_acceleration = 7.5,

	idle_rotation_rate = 0.5,
	walk_rotation_rate = 4.0,
	run_rotation_rate = 5.0,
	sprint_rotation_rate = 20.0,
}

Movement Variables :

when you change them they update the character status like is it crouching / running , etc most of them are using the @export

@export var is_flying := false @export var gravity := 9.8

@export var jump_magnitude := 5.0 @export var roll_magnitude := 17.0

var default_height := 2.0 var crouch_height := 1.0

@export var crouch_switch_speed := 5.0

The Movement Status :

@export var rotation_mode = Global.rotation_mode (velocity_direction , looking_direction , aiming)

@export var gait = Global.gait (walking , running , sprinting)

@export var stance = Global.stance (standing , crouching)

@export var overlay_state = Global.v (default , rifle , pistol)