Created
June 6, 2023 04:27
-
-
Save fackux/1fb9d34d2e9284d978ea08780cc91680 to your computer and use it in GitHub Desktop.
Godot Movimiento
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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