Hi, I'm learning Godot and was having a hard time to figure this out and couldn't find any tutorials that helped with my problem. So I am learning by trying to create a 2d top down shooter so right now I'm trying to get my players movement to move according to which way he is facing. I have the player looking at the mouse cursor but the player will always go up when I press 2. If anyone could help me that would be greatly appreciated :) my code so far is located below.
extends KinematicBody2D
var MAX_SPEED = 500
var ACCELERATION = 4000
var motion = Vector2.ZERO
func _physics_process(delta):
var axis = get_axis()
if axis == Vector2.ZERO:
apply_friction(ACCELERATION * delta)
else:
apply_movement(axis * ACCELERATION * delta)
motion = move_and_slide(motion)
look_at(get_global_mouse_position())
func get_axis():
var axis = Vector2.ZERO
axis.x = int(Input.is_action_pressed("right")) - int(Input.is_action_pressed("left"))
axis.y = int(Input.is_action_pressed("down")) - int(Input.is_action_pressed("up"))
return axis.normalized()
``
func apply_friction(amount):
if motion.length() > amount:
motion -= motion.normalized() * amount
else:
motion = Vector2.ZERO
func apply_movement(acceleration):
motion += acceleration
motion = motion.clamped(MAX_SPEED)