godot 4
For my game I want a enemy to shoot a bullet at the player, I do this by making it look at the player and shooting it. The issue is that the bullet cant be dodged and always hit, I have tried adding an offset of a random number but i get the error
Invalid operands ‘Vector2’ and ‘float’ in operator ‘+’.
here is my code
@onready var player = get_node(“/root/bossRoom/Player”)
var random = randf()
func _physics_process(_delta):
var position = player.global_position
position += random
look_at(position)
func shoot():
const BULLET = preload(“res://Scenes/bullet.tscn”)
var new_bullet = BULLET.instantiate()
new_bullet.global_position = %laserPoint.global_position
new_bullet.global_rotation = %laserPoint.global_rotation
%laserPoint.get_parent().add_child(new_bullet)
thanks for any help