When I shoot diagonally up and right/left at the same time, the shoot doesn't work, how do I solve this problem?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By andre3319

I’ve started recently with Godot, and I’m trying to create a spaceship, but when I shoot, it doesn’t work when I shoot diagonally up and right or diagonally up and down.

extends Node2D

const PRE_LASER = preload("res://scenes/laser.tscn")

var vel = 60

func _ready():

func _process(delta): 
	var dirX = 0
	var dirY = 0

   	 if Input.is_action_pressed("ui_left"):
		dirX += -1
	if Input.is_action_pressed("ui_right"):
		dirX += 1
	if Input.is_action_pressed("ui_down"):
		dirY += 1
	if Input.is_action_pressed("ui_up"):
		dirY += -1

    if  Input.is_action_just_pressed("ui_accept"):
		if get_tree().get_nodes_in_group("lasers").size() < 3:
			var laser = PRE_LASER.instance()
			laser.global_position = $blaster.global_position

translate(Vector2(dirX,dirY) * vel * delta)

global_position.x = clamp(global_position.x,21,139)
global_position.y = clamp(global_position.y,24,268)
:bust_in_silhouette: Reply From: MadTinkerer

What exactly doesn’t work? Do the lasers not appear?

Yes, exactly.

andre3319 | 2022-04-08 11:55

And it’s fine when you’re shooting in any other direction?

MadTinkerer | 2022-04-09 07:05

I’m sorry for taking too long to answer. The only directions it does not work is diagonal up and down, both to the right. The other directions work perfectly.

andre3319 | 2022-05-01 12:55