0% found this document useful (0 votes)
12 views

Movimiento

The document outlines the process of creating a 2D movement system in Godot using GDScript. It explains the use of Vector2 for movement direction, the Input.is_action_pressed() function for detecting user input, and the setup of a Player node with movement properties. Additionally, it covers exporting variables for easy editing in the Godot editor and the importance of the _process function for regular updates in the game loop.

Uploaded by

233112045
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Movimiento

The document outlines the process of creating a 2D movement system in Godot using GDScript. It explains the use of Vector2 for movement direction, the Input.is_action_pressed() function for detecting user input, and the setup of a Player node with movement properties. Additionally, it covers exporting variables for easy editing in the Godot editor and the importance of the _process function for regular updates in the game loop.

Uploaded by

233112045
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Función de 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?

● A 2D vector is a mathematical entity with two components:


○ x: Represents the horizontal component.
○ y: Represents the vertical component.

Explanation, 2
Input.is_action_pressed()

● 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:

● Returns true if the specified action is currently being pressed.


● Returns false if the specified action is not being pressed.
Activar Acciones integradas de Mapa de entrada
Nuevo Nodo 2D
Crear un Nodo 2D
Guardar escena
Hacerla principal
Nodo hijo
Para Node 2D, del tipo

CharacterBody2D
Renombrar nodo
Como Player
Agregar script
Nombrar “player”
Redefinir script
extends CharacterBody2D

''' MOVIMIENTO 2D '''

# Variables de movimiento del personaje.

@export var speed : float

func _process(delta):

motion_ctrl()

func motion_ctrl() -> void:

velocity.x = GLOBAL.get_axis().x * speed

velocity.y = GLOBAL.get_axis().y * -speed

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): This is a parameter of the _process function.

● 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!

You might also like