Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | pion |
I am making a 2D sidescrolling shooter and just got the code to shoot a bullet working. I created a second scene named “Bullet” with an Area2D, a sprite and a collision box as a child of area2d. I have a player script in my main scene
Code for the Area2D node:
extends Area2D
func _ready():
pass
func _physics_process(delta):
position.x += 10
Code for the player (only shooting part)
onready var BULLET = preload("res://Bullet.tscn")
func _process(delta):
if Input.is_action_just_pressed("shoot"):
var bullet = BULLET.instance()
get_node("/root/Game").add_child(bullet)
bullet.global_position = $Position2D.global_position
I would like the bullet to get deleted when colliding with any objects in my game (This mainly includes a tileset with collision detecion). I read you could link body_entered with a body of your choice, but the tileset is in the main scene and its nodes are not listed under the node tab.
How do I go about detecting collision for this Area2D in another scene?