how to shoot to both direction?

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

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

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?

fpicoral | 2019-01-26 21:54

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

thoma | 2019-01-27 00:16

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.

fpicoral | 2019-01-27 02:05

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

thoma | 2019-01-27 16:48

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

fpicoral | 2019-01-27 16:56

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

problem

thoma | 2019-01-27 17:11

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

fpicoral | 2019-01-27 17:20

thank you a lot

thoma | 2019-01-27 17:50