0 votes

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

1 Answer

0 votes

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

by (39 points)

Yes, exactly.

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

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.

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 Frequently asked questions and 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.