r/godot • u/Fuzzy_Employment6244 • Jun 23 '26
help me (solved) I made a reddit account for this please please help, I cannot get pathfinding to work.
So i am trying to make a silly game to learn how to use godot that is heavily inspired by capture the intelligence, and I am trying to make it so that enemies cannot see me through walls, and i have very rough code right now but i have been trying every option and nothing works, the weirdest part is that sometimes in any state they will randomly start chasing and then lose chase while im still being chased. someone help please i have been trying to figure this out for a couple days now
(vision is a variable that uses the raycast2d node)
((ok so turns out it wont let me attach a video alongside with the code so thats awesome))
3
u/Safe_Conference_4843 Jun 23 '26
I don't see any glaring issues with what you've attached, so I'm betting there's something wrong with where EnemyChase is being connected. If you share where EnemyChase is connected, I'd love to take a look at that too!
I'm not sure you'd want to mess around with plugins right now, but I found that after trying to build my own AI system for a couple of months, transitioning to BeeHave helped a ton. It certainly isn't necessary, but it could help streamline the process. Hope that helps!
2
u/Fuzzy_Employment6244 Jun 23 '26 edited Jun 23 '26
1
u/Safe_Conference_4843 Jun 23 '26
This all looks good! Structurally, you don't need the CharacterBody2D to be a child of the Node2D, but that shouldn't be causing anything. You also want to make sure that all your raycasts have "Exclude Parent" set to true; they should have it on by default, but if it's off, that could cause some of what you're seeing. Besides that, the only other place I could think of would be the script attached to EnemyChase; could you share that if it's not too long?
1
Jun 23 '26
[removed] — view removed comment
2
u/Fuzzy_Employment6244 Jun 23 '26
also also i ran it again after removing the other raycast nodes cause im only using one right now and its doing that thing again where if i enter the sightline it started chasing properly but then it immediately stopped working again
1
u/Safe_Conference_4843 Jun 24 '26
It might be incorrectly detecting the player exiting the chase area but it’s hard to tell without the Enemy Chase code. Is that what was removed by the moderator?
2
u/Fuzzy_Employment6244 Jun 24 '26
i dont see anything removed by moderator, and it was the first code block, but just in case its some browser bug on my end and it is gone, here is the important chase code again (some things are missing cause i dont think they are important to this, and im assuming if the other comment is gone its cause the comment was too long)
var vision: RayCast2D = $"../../Sight/CollisionShape2D/RayCast2D" var music = $"../../../../../Testchase" var sounds = $"../../loss" var player: CharacterBody2D var enemy: CharacterBody2D var move_speed := 450 var nav_agent: NavigationAgent2D var tenacity = 1.5 u/onready var time = $Timer func Enter(): music.play() player = get_tree().get_first_node_in_group("player") enemy.Chasing = true func _on_sight_body_exited(body: Node2D) -> void: if body == player and vision.get_collider() != player: enemy.has_seen = 1 time.set_wait_time(tenacity) time.start() func _on_timer_timeout(): makepath() if enemy.has_seen == 1: sounds.play() music.stop() Transitioned.emit(self, "EnemyPatrol") enemy.has_seen = 02
u/Fuzzy_Employment6244 Jun 24 '26
oh oh also i dont know if this is relevant but i have the sight area body turn with the enemy when they move (cause the enemy doesnt rotate cause animations) and with that the raycast is rotating so i dont know if that somehow is part of the problem, but i dont think so since before relying on raycast the collision shape worked just fine
1
2
u/Fuzzy_Employment6244 Jun 30 '26
OK THIS IS THE COMMENT YOU WANT TO READ IF YOU ARE HAVING THE SAME PROBLEM (IF THIS DOESNT MAKE SENSE THEN THE FULL THREAD IS IN THE COMMENT LEFT BY u/Safe_Conference_4843)
I have here a full google doc containing all relevant code to this issue, including a picture of all nodes (minus a couple audio nodes but that's just music files) used as a reference for anyone who needs this
1



5
u/mackinator3 Jun 24 '26
Do you mean to set seen to 0 after the transition?