Godot Version
Godot 4.5.1 stable
Question
I’ve been trying to code an enemy for a while, I decided it was best before focusing on combat elements.
It’s getting there, my raycast is actually following the player now, however for some reason I can’t get the projectile to spawn. The conditions are set. I have a check in my projectile launcher script and it’s come up with true. So I’m very confused as to why this isn’t working. Help is appreciated.
extends CharacterBody3D
@onready var ray = $RayCast3D
const bullet = preload("res://bullet.tscn")
#var can_fire: bool = fireNow.playerSpotted
func _ready() -> void:
pass
func _physics_process(delta: float) -> void:
var target = Vector3(Autoload.player.position.x, Autoload.player.position.y, Autoload.player.position.z)
var direction = position + target
var direction_to_Player = target - global_position
ray.target_position = ray.to_local(target)
rotation.z = lerp_angle(rotation.z, atan2(direction_to_Player.x, direction_to_Player.y), delta/10)
#var targetPosition = ray.direction_to(Autoload.player)
if Autoload.playerSpotted == true:
fire()
if Input.is_action_just_pressed("check"):
print(Autoload.playerSpotted)
func fire():
var shoot = bullet.instantiate()
add_sibling(shoot)