Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Lapa |
I have been watched some other discussion about this and tried some things but i haven’t found the solution. I try to make the character to goto his spawnpoint after he got died.
but always came this
Invalid set index ‘position’ (on base: ‘PackedScene’) with value of type ‘Vector2’.
my code:
extends KinematicBody2D
export (PackedScene) var body
export var health = 6
var dash_timer = 200
signal dead
signal damage_taken
export var speed = 180
export var jump_force = 400
const UP = Vector2(0, -1)
var velocity = Vector2()
func _ready():
show()
$CollisionShape2D.disabled = false
func _process(delta):
$Sprite.play()
dash_timer -= 1
if Input.is_action_pressed("d"):
velocity.x = speed
$Sprite.stop()
elif Input.is_action_pressed("a"):
velocity.x = -speed
$Sprite.stop()
else:
$Sprite.animation = "Idle"
velocity.x = 0
if is_on_floor():
velocity.y = 0
if Input.is_action_pressed("space"):
velocity.y = -jump_force
velocity = move_and_slide(velocity, UP)
if !is_on_floor():
velocity.y += 10
if Input.is_action_pressed("s") && dash_timer < 10:
dash_timer = 200
velocity.y += 400
func _on_Area2D_body_entered(body):
emit_signal(“damage_taken”)
health -= 1
speed += 20
func _on_HUD_dead1():
$CollisionShape2D.disabled = true
hide()
body.position = Vector2(64, 448)
$CollisionShape2D.disabled = false
show()