Enemy AI | it works but?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By morningkingdom

Hi there people, i made a crude ai for my enemies. its work but im sure it can be better. and im new at codding and game dev. , so am not sure what is a good ai and what is not. so i need suggestions.

this is my ai code:
note : i did use 3 diffrent timer for 3 diffrent state.

var rotate_y_speed = 0.5
var rotate_y_degree
var enemy_speed = -0.1
enum {
    forward,
    rotate,
    stop
}
var state = forward
var forward_timer_random = RandomNumberGenerator.new()
var forward_timer_range
var stop_timer_random = RandomNumberGenerator.new()
var stop_timer_range
var rotate_timer_random = RandomNumberGenerator.new()
var rotate_timer_range
func _on_enemy1_forward_timeout():
    state = forward
func _on_enemy1_stop_timeout():
    state = stop
func _on_enemy1_rotate_timeout():
    state = rotate
func _process(delta):
    randomize()
    forward_timer_range = forward_timer_random.randf_range(0,1)
    stop_timer_range = stop_timer_random.randf_range(0,1.5)
    rotate_timer_range = stop_timer_random.randf_range(0,3)
    $enemy1_forward.start(forward_timer_range)
    $enemy1_stop.start(stop_timer_range)
    $enemy1_rotate.start(rotate_timer_range)
    match state:
        forward:
            translate(Vector3(0,0,enemy_speed))
        stop:
            translate(Vector3(0,0,0))
        rotate:
            rotate_y_degree = rotate_y_speed * delta
            rotate_y(rotate_y_degree)

and this is the output:
enter link description here

If the AI behaves the way you want it to, its good AI. At least thats the way I see it. Is there anything that you want them to do differently, or are you just looking for ideas? :slight_smile:

Millard | 2020-11-09 18:39

Well, actually im not sure what kind of game it Will be.
So i think at the Late stages i Will Change the ai,
So i need suggestions for the code part and examples to see
Different kind of ai (basic or not) algorithms. To study.

morningkingdom | 2020-11-09 19:37