0 votes

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)
Godot version 3.3.2
in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.