Second type of enemy movement

Godot Version

4.6.

Question

Hello,

I am trying to make it so that, when I shoot the enemy, it goes from completely random movement (on all axes) to random movement on a single axis (facing the player, to simulate a “strafe”).

I used print to check that it works but, no matter what I try, nothing works. (X

Thanks to those who have advice. ^^

‘‘‘func _straf():
$RayCast3D.collide_with_bodies = true
if _current_health < max_health :
$RayCast3D.collide_with_bodies()
var coll = $RayCast3D.get_collider()
if coll != null and coll.name == $“../JOUEUR”:
coll.print(“LOL”)’’’

func _ready():
$RayCast3D.collide_with_bodies = true

func _physics_process(delta: float) -> void:
    if $RayCast3D.is_colliding():
        var collision_point = $RayCast3D.get_collision_point()
        var collider = $RayCast3D.get_collider()
        print("Hit: ", collider.name, " at ", collision_point)

Try something like this to get started.

Sorry for the delayed response, I've had some issues and haven't been coding lately.

I've been thinking about it and I think I can do it without raycasting. I just need to figure out how to make the bot go from moving randomly in all directions to moving left and right towards the player when I shoot it. ^^
Currently, my movement code looks like this:

‘‘‘func _on_random_timer_timeout() → void:

var x = randi_range(-1,1)
var z = randi_range(-1,1)
var dir = Vector3(x,0,z).normalized()
velocity = speed * dir
$RandomTimer.start_random()
if $"." take_damage():
	$"." look_at(player.position)'''
The "look at" function doesn't seem to work, and besides, I don't even know how to tell it to look left and right in front of the player, since the player's position can change, so the left and right directions aren't always on the same axis. ^^