There is a project in it there is a player enemies and a bullet. The script is to the enemy and to the player. The game does not want to start and writes that the error in the script of the enemy 11 tape.
script for the player:
enter code here
extends KinematicBody2D
var movespeed = 500
var bullet_speed = 1500
var bullet = preload("res://bullet.tscn")
func ready():
pass # Replace with function body.
func _physicsprocess(delta):
var motion = Vector2()
if Input.is_action_pressed("up"):
motion.y -= 1
if Input.is_action_pressed("down"):
motion.y += 1
if Input.is_action_pressed("right"):
motion.x += 1
if Input.is_action_pressed("left"):
motion.x -= 1
motion = motion.normalized()
motion = move_and_slide(motion * movespeed)
look_at(get_global_mouse_position())
if Input.is_action_just_pressed("LMB"):
fire()
func fire():
var bulletinstance = bullet.instance()
bulletinstance.position = getglobalposition()
bulletinstance.rotationdegrees = rotationdegrees
bulletinstance.applyimpulse(Vector2(),Vector2(bulletspeed,50).rotated(rotation))
gettree().getroot().calldeferred("addchild",bullet_instance)
func kill():
gettree().reloadcurrent_scene()
func onArea2Dbodyentered(body):
if "Enemy" in body.name:
kill()enter code here
the code for the enemy is,
`enter code here`extends KinematicBody2D
var motion = Vector2()
func _ready():
pass # Replace with function body.
func physicsprocess(delta):
var Player = getparent().getnode("Player")
position += (Player.position - position)/50
look_at(Player.position)
move_and_collide(motion)
func onArea2Dbodyentered(body):
if "bullet" in body.name:
queue_free()enter code here
error in the enemy code in this line:
position + = (Player.position - position) / 50
writes here such error.
Invalid get index 'position' (on base: 'null instance').
and this is - E 0: 00: 00.631 get_node: Node not found: Player.
Condition "! Node" is true. Returned: __null
scene / main / node.cpp: 1381 @ get_node ()
Enemy.gd:9 @ _physics_process ()
so does anyone know a fix for this?