everything is as it says in the title. I have no experience in creating an inventory and I found a video cycle with an explanation of what needs to be done. actually, the video itself is below. the problems start at 12: 15, because the code considers the pickupitem function non-existent when i'm trying to interact.
I'm sorry if this format of the question offends you, but I really can't find a solution. I will be glad of any help, have a good day
below will be the code and video itself
https://www.youtube.com/watch?v=ssYqIQQPt7A&t=843s
player (that one part):
func _input(event):
if Input.is_action_just_pressed("takeitem"):
if $itemdrop.itemsinrange.size() > 0:
var pickitem = $itemdrop.itemsinrange.values()[0]
pickitem.pick_up_item(self) #пофиксь пик ап итем пж, оно не видит функцию в сцене drop((((((
$itemdrop.itemsinrange.erase(pickitem)
drop:
extends KinematicBody2D
const ACCELIRATION = 700
const MAX_SPEED = 95
var velocity = Vector2.ZERO
var itemname
var player = null
var being_picked_up = false
func _ready():
itemname = "Монстро-конфета"
func _physics_process(delta):
if being_picked_up == true:
var direction = global_position.direction_to(player.global_position)
velocity = velocity.move_toward(direction * MAX_SPEED, ACCELIRATION * delta)
var distance = global_position.distance_to(player.global_position)
if distance < 10:
PlayerInv.add_item(itemname, 1)
queue_free()
velocity = move_and_slide(velocity, Vector2.UP)
func pick_up_item(body):
player = body
being_picked_up = true