Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | popstick |
extends Area2D
var drag = false
var posX = 0
var posY = 0
onready var player = $player
onready var FirPos = $FirePos
var Gbullet = preload(“res://Scenes/Node2D.tscn”)
func _input(event):
if event is InputEventMouseButton:
if event.is_action_pressed(“click”):
drag = true
if event.is_action_pressed(“click”):
for child in FirPos.get_children():
var bullet = Gbullet.instance()
bullet.global_position.x = child.global_position.x
bullet.global_position.y = child.global_position.y
get_tree().current_scene.add_child(bullet)
if drag:
posX = event.position.x
posY = event.position.y
func _physics_process(delta):
if drag:
player.global_position.x = posX
player.global_position.y = posY
var viewRect = get_viewport_rect()
posX = clamp(posX,0,viewRect.size.x)
posY = clamp(posY,0,viewRect.size.y)
the problem may be here
for child in FirPos.getchildren():
var bullet = Gbullet.instance()
bullet.globalposition.x = child.globalposition.x
bullet.globalposition.y = child.globalposition.y
gettree().currentscene.add_child(bullet)
Try . i didn’t check
for child in FirPos.getchildren():
var bullet = Gbullet.instance()
bullet.global_position = global_position ## Area2d global position
get_tree().current_scene.add_child(bullet)
Or
https://www.youtube.com/watch?v=MVIYnhKN260
ramazan | 2022-10-14 08:13