LoseriamVM

  • Jul 3, 2023
  • Joined May 9, 2023
  • 0 best answers
  • extends KinematicBody2D
    
    
    var velocity = Vector2()
    export var direction = -1
    
    func _ready():
    	if direction == -1:
    		$AnimatedSprite.flip_h = true
    
    func _physics_process(delta):
    	
    	if is_on_wall():
    		direction = direction * -1
    		$AnimatedSprite.flip_h = not $AnimatedSprite.flip_h
    	
    	velocity.y += 10
    	
    	velocity.x += 25 * direction
    	
    	velocity = move_and_slide(velocity,Vector2.UP)
  • Im making a chest and it is supposed to drop a key. When i open it it closes the current play test and im not very good with GD script so i dont know how to fix it

    extends AnimatedSprite
    
    export(PackedScene) var object_scene: PackedScene = null
    
    var is_player_inside: bool = false
    var is_opened: bool = false
    
    onready var animation_player: AnimationPlayer = get_node("AnimationPlayer")
    onready var tween: Tween = get_node("Tween")
    
    func _ready() -> void:
    assert(object_scene != null)
    animation_player.play("Idle")
    
    func _input(event: InputEvent) -> void:
    if event.is_action_pressed("Interact") and is_player_inside and not is_opened:
    is_opened = true
    animation_player.play("Open")
    
    func _drop_object() -> void:
    var object: Node2D = object_scene.instance()
    owner.get_node("Objects").add_child(object)
    func on_Area2D_player_entered(player: KinematicBody2D) -> void:
    is_player_inside = true
    
    func on_Area2D_player_exited(player: KinematicBody2D) -> void:
    is_player_inside = false

    It says the problem is right here:

    func _drop_object() -> void:
    var object: Node2D = object_scene.instance()
    owner.get_node("Objects").add_child(object)

    function 'add_child' in base 'null instance' on a null instance
    at function: _drop_object

    if anyone knows whats wrong please help

    • xyz replied to this.