The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

actualy I am trying to make the bullet shoot to the right and the left but the problem is the bullet don't want to appear where I positionate the Position2d. Thank to helping me.

the position of my Position2D:(x-100.712006,y-41.720001)(it just shot to left were I wanted to but went I shoot to the left the bullet appear too munch far)
(in a scene) the position of my VisibilityNotifier:(x0,y-9)

(the code of my scene character)

extends KinematicBody2D

const vitesse = 50
const gravite = 10 
const saut_puissance = -250
const plancher = Vector2(0, -1)

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

var sur_sol = false


var mouvement = Vector2()

func _physics_process(delta):

    if Input.is_action_pressed("ui_right"):
        mouvement.x = vitesse
        $AnimatedSprite.play("walk")
        $AnimatedSprite.flip_h = true
        if sign($Position2D.position.x) == -1:
            $Position2D.position.x *= -1


    elif Input.is_action_pressed("ui_left"):
        mouvement.x = -vitesse
        $AnimatedSprite.play("walk")
        $AnimatedSprite.flip_h = false
        if sign($Position2D.position.x) == 1:
            $Position2D.position.x *= -1

    else:
        mouvement.x = 0
        if sur_sol == true:
            $AnimatedSprite.play("idle")

    if Input.is_action_pressed("ui_up"):
        if sur_sol == true:
            mouvement.y = saut_puissance
            sur_sol = false

    if Input.is_action_just_pressed("ui_shoot"):
        var laser = LASER.instance()
        if sign($Position2D.position.x) == 1:
            laser.set_laser_direction(1)
        else:
            laser.set_laser_direction(-1)
        get_parent().add_child(laser)
        laser.position = $Position2D.global_position

    mouvement.y += gravite

    if is_on_floor():
        sur_sol= true
    else:
        sur_sol = false
        if mouvement.y < 0:
            $AnimatedSprite.play("jump")
        else:
            $AnimatedSprite.play("fall")

    mouvement = move_and_slide(mouvement, plancher)

(The code of my scene laser/bullet)

extends Area2D

const speed =100
var velocity =Vector2()

var direction = 1

func set_laser_direction(dir):
    direction = dir
    if dir == -1:
        $AnimatedSprite.flip_h = true

func _physics_process(delta):
    velocity.x = speed * delta * direction
    translate(velocity)
    $AnimatedSprite.play("shoot")

func _on_VisibilityNotifier2D_screen_exited():
    queue_free()

If you need more information please telling me
(thank to answer)

some picture of my problem

in Engine by (78 points)
edited by

What is actually the problem and what do you want to achive? If I understood right, you want that when the button "ui_shoot" is pressed the character shoot to both left and right at the same time but it's not working?

What might be is that you are instanciating it as a child of the player not the map so its position is relative to the player, but I'm not sure about that.

Could you share the project so I can have a better look at the problem?

Ok, I just puted evrything I used in a folder.
the link:Game Folder

You did not upload the project, but just some files.Go to your project's folder and upload the WHOLE folder EXACTLY how it is, otherwise I won't be able to open the project here.

finally, it suposed to work.I export it in .zip,.pck and .pck.tmp.

You are not doing this right... Go to where you saved your project, the folder should look like that:
(of course will be a litte different deppending of what files/folders you created/imported to your project)

enter image description here

  1. Copy ALL files and folders inside the project folder, just do CTRL+A
    and then CTRL+C
  2. Create a new folder. The name does not matter
  3. Open this folder and hit CTRL+C
  4. Upload this new folder you created somewhere like Google Drive and send the link

If you don't follow these steps I won't be able to help you

I follow all of your steps now it suposed to work correctly
the link:

problem

Your project has a ton off problems, not only in organization but things like scaling coliision shapes, copying and pasting instead of using a TileMap, etc.

I would strongly recommend this course since you are a very begginer: https://www.udemy.com/godot

thank you a lot

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 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 [email protected] with your username.