Skip to content

Instantly share code, notes, and snippets.

@fackux
Created June 6, 2023 04:27
Show Gist options
  • Save fackux/1fb9d34d2e9284d978ea08780cc91680 to your computer and use it in GitHub Desktop.
Save fackux/1fb9d34d2e9284d978ea08780cc91680 to your computer and use it in GitHub Desktop.
Godot Movimiento
extends Node
var score : int
# Movimiento del player, ejes de movimiento.
var axis : Vector2
# Función para retornar la dirección pulsada.
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()
extends CharacterBody2D
''' MOVIMIENTO 2D '''
# Presten mucha atención, porque esto ya es el script del personaje, no el autoload ¿sí?
# ¿No querían aprender? Pues se me ponen vivos...
# 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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment