See all glossary terms

Basis

In 3D space, a basis represents the rotation and scale part of a transform. It defines an object's orientation and size through three perpendicular vectors (axes) that form a coordinate system: the object's own x, y, and z axes.
You can think of a basis as describing "which way is up, right, and forward" for an object in your 3D world. You can also stretch or shrink these axes to scale the object along each direction.
The basis is represented by the Basis type in Godot. All 3D nodes have a basis property that you can access and modify to change the object's orientation and scale (this is a shortcut for transform.basis, which is the same value).
The basis has three Vector3 properties accessible like this:
  1. basis.x: The right direction (x-axis)
  2. basis.y: The up direction (y-axis)
  3. basis.z: The forward/back direction (z-axis)
Here's an example showing a common way to use the basis to move a character in 3D space. Here the character can move forward and back or strafe left and right based on its orientation:
func _process(delta: float) -> void:
	var direction: Vector3 = Vector3.ZERO
	if Input.is_action_pressed("move_forward"):
		direction -= transform.basis.z
	if Input.is_action_pressed("move_backward"):
		direction += transform.basis.z
	if Input.is_action_pressed("move_right"):
		direction += transform.basis.x
	if Input.is_action_pressed("move_left"):
		direction -= transform.basis.x
	direction = direction.normalized()

	position += direction * speed * delta
This video clip illustrates the basis in Godot
It's helpful to visualize the basis as the three colored axes you see when you select an object in the 3D editor. When you rotate an object, you're actually rotating these axes. When you scale it, you're changing the length of the axes.

See Also

Related terms in the Glossary