Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+1)

Hello! I think you did a great job on hooking up the animations for running, jumping, and falling really well. I am also a Godot developer using 4.2 (about to go to 4.3). I think you should check out Brackey's new Godot tutorial on Youtube if you want to try again or to try fixing up the features you mentioned.  The video covers everything you wanted to add and I think it would really help.


In my top down game I used the Player's position to force the enemies (called Hero in code) to walk directly towards the Player and an Area2D node to detect if they reached the player to stop them from moving so that they can shoot. This is different than what the Brackey's video did, but it might give you an idea for the future.  I modified my code a bit to show the important bits. 

The part that says "if body is Player" works because the Player script starts with "class_name Player extends CharacterBody2D" so Godot can recognize it in other scripts for certain things. In this example, all of my enemies and the player are attached to a main scene called Map01, so I am able to get the map in the enemy script and the first child of the map which is the player. This is by far the clunkiest script you could use, but it works.


class_name Hero extends CharacterBody2D
@onready var map = get_tree().root.get_node("Map01")
@onready var player = $Player
var can_move = true
#physics for a CharacterBody2D
func _physics_process(delta):
    if can_move == true:
        var player_position = map.get_child(0).global_position
        move_direction = (player_position - global_position).normalized()      
    else:
        velocity = Vector2(0,0)
    
    move_and_slide()
    update_anim()
#Area2D node signals
func _on_body_entered(body):
    if body is Player:         can_move = false func _on_body_exited(body):     if body is Player:         can_move = true

Thank you very much for the direction. I had plans to check out Brackey's new videos very soon, but I didn't think he would cover pathfinding of this sort. The method I was using (from another tutorial, based in 3.x Godot) used raytracing to generate points the enemies could move between. I wanted to make sure the enemies could follow the player up cliffs and across jumps. But, the raytracing refused to detect collisions with the tilemap, so my next goal is to learn more about the raytracing systems in Godot.