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