![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Large Sleeves |
Hi
I can’t seem to find out what I’m doing wrong here. I have it so the player can create bombs but currently whenever you try to do so it crashes. The error that shows up is Invalid set index ‘position’ (on base:‘PackedScene’) value of type ‘Vector2’.
Here is the relevant code.
const BOMB = preload("res://source/actors/Bomb.tscn")
func _physics_process(delta):
if Input.is_action_pressed("Move_right"):
velocity.x = SPEED
$anim.play("walking right")
$anim.flip_h = false
elif Input.is_action_pressed("Move_left"):
velocity.x = -SPEED
$anim.play("walking right")
$anim.flip_h = true
else:
velocity.x = 0
if on_ground == true:
$anim.play("1")
if Input.is_action_just_pressed("place_bomb"):
if on_ground == true:
velocity.y = JUMP_POWER
on_ground = false
if Input.is_action_just_pressed("place_bomb"):
var t = Timer.new()
t.set_wait_time(0.15)
t.set_one_shot(true)
add_child(t)
t.start()
yield(t, "timeout")
var bomb = BOMB.instance()
get_parent().add_child(bomb)
BOMB.position = $Position2D.global_position
var BOMB = BOMB.instance()
World.add_child(BOMB)
(I have code in between but it is irrelevant variables that aren’t the problem.) The point at which it crashes is at ‘BOMB.position = $Position2D.global_position’. I think it has to do with the way I’m preloading the bomb. It is a node2D. Sorry for the long mess.
Thanks for the help!
-“The new guy”