Movimiento
Movimiento
Alternativa
Crear un autoload y activarlo
1 derecha, 0 neutro, -1 izquierda
extends Node
var score : int
var axis : Vector2
func get_axis() -> Vector2:
axis.x = int(Input.is_action_pressed("ui_right"))-int(Input.is_action_pressed("ui_left"))
axis.y =
int(Input.is_action_pressed("ui_up"))-int(Input.is_action_pressed("ui_down"))
return axis.normalized()
Explanation
● var axis : Vector2
What is a Vector2?
● This function checks if a specific action defined in your project's input map is currently
being pressed.
Syntax: Input.is_action_pressed("action_name")
● action_name: This is a string that corresponds to the name of the action you've defined
in your project's input map.
Return Value:
CharacterBody2D
Renombrar nodo
Como Player
Agregar script
Nombrar “player”
Redefinir script
extends CharacterBody2D
func _process(delta):
motion_ctrl()
move_and_slide()
Explanation
@export: This is a special keyword in GDScript that marks a variable as an "exported"
property.
● Exported properties are visible and editable within the Godot editor's Inspector panel for
the specific node that uses this script.
● This allows you to easily adjust the value of the variable without needing to modify the
script directly
Explanation, 2
func: This keyword signifies the beginning of a function definition.
_process: This is a special function name in Godot. When a node has a _process
function, it signals to the engine that this node needs to be updated regularly.
● delta represents the time elapsed since the last frame in seconds.
● This value is crucial for ensuring consistent game behavior across different
hardware and frame rates.
Definir velocidad de nodo Player
100
Nuevo nodo hijo
Para Player, del tipo
sprite2D
Texture
Añadir
icono de Godot
a Inspector, Texture
Estructura
¡Dale Play!