Skip to content

GDScript overview

Posted on:August 10, 2024 at 03:36 PM

Basic terms

if direction:
	velocity.x = direction.x * SPEED
	velocity.z = direction.z * SPEED
else:
	velocity.x = move_toward(velocity.x, 0, SPEED)
	velocity.z = move_toward(velocity.z, 0, SPEED)

Common standard functions

Working with settings

var gravity = ProjectSettings.get_setting("physics/3d/default_gravity");

This gravity value is set in Settings -> General -> Physics -> 3D. Other settings could be accessed in the similar manner. When default settings are changed, project.godot file is being updated with the corresponding values.

Here’s an example of changing the default gravity value in settings:

[physics]

3d/default_gravity=9.5

Getting keys

Keys = actions.

Handling example:

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	if Input.is_action_pressed("ui_left"):
		rotate_y(deg_to_rad(-ROTATION_SPEED))
	else:
		if Input.is_action_pressed("ui_right"):
			rotate_y(deg_to_rad(ROTATION_SPEED))

elif:

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	if Input.is_action_pressed("ui_left"):
		rotate_y(deg_to_rad(-ROTATION_SPEED))
	elif Input.is_action_pressed("ui_right"):
		rotate_y(deg_to_rad(ROTATION_SPEED))

Most useful docs pages

Overridable functions