I am new to coding and I'm currently working on a 2d platform game where I am trying to have pickup items. I have a collectables scene and script and I also wrote it into my level scene with func spawn_pickups(): I have the items on a collectables layer and the mask is set to player yet when I try to pick them up, they are acting like a wall and my player either runs into them or stands on them.
Here is my code for the collectable:
extends Area2D
signal pickup
var textures = {'coin': 'res://assets/coin.png',
'fly': 'res://assets/fly.png'}
func init(type, pos):
$Sprite.texture = load(textures[type])
position = pos
func _on_Collectable_body_entered(body):
emit_signal('pickup')
queue_free()
Here is the code for my level:
extends Node2D
signal score_changed
var score
var Collectable = preload('res://items/Collectable.tscn')
onready var pickups = $Pickups
func _ready():
score = 0
emit_signal('score_changed', score)
pickups.hide()
$Player.start($PlayerSpawn.position)
#set_camera_limits()
spawn_pickups()
func set_camera_limits():
var map_size = $World.get_used_rect()
var cell_size = $World.cell_size
$Player/Camera2D.limiit_left = (map_size.position.x - 5) * cell_size.x
$Player/Camera2D.limiit_right = (map_size.position.x + 5) * cell_size.x
func spawn_pickups():
for cell in pickups.get_used_cells():
var id = pickups.get_cellv(cell)
var type = pickups.tile_set.tile_get_name(id)
if type in ['coin', 'fly']:
var c = Collectable.instance()
var pos = pickups.map_to_world(cell)
c.init(type, pos + pickups.cell_size/2)
add_child(c)
c.connect('pickups', self, 'on_Collectable_pickup')
func _on_Collectable_pickup():
score += 1
emit_signal('score_changed', score)
func _on_Player_dead():
pass
any ideas and help is very appreciated, thank you in advance