Could someone help me with an issue I have in my game? I'm making a stealth game and decided to use state machines for both the player's and enemy's behaviour. I'm new to state machines so I don't know if I got it right, but because of it I've run into issues I don't know how to solve. One of the issues is that during the enemy's Idle state, they're supposed to generate multiple area3Ds that will be placed at each corner of the Path3D. This way when the enemy touches one of the points, they will stop moving on the path for 3 seconds before continuing their patrol. At first it was working perfectly, that was until I tried making multiple enemies.
For some reason, it just stops generating the Area3Ds at the position of the points, even though it prints that it does. I don't know if this is an issue with the script itself or maybe some settings I didn't do right. The other issue I have is that gravity doesn't affect the player when they're moving, so when they fall off a ledge, as long as they're holding onto "W" key they'll keep moving in the air.
#Issue with Stealth Game
2 messages · Page 1 of 1 (latest)
This is the script for the enemy Idle State ```py
extends State
class_name EnemyIdle
var marker_instance = preload('res://Scenes/Objects/stopping_points.tscn')
@export var enemy : CharacterBody3D
@export var Path : Path3D
@export var PathFollow : PathFollow3D
@export var move_speed = 4
@export var wait_time : Timer
var can_patrol = true
@onready var vision_area: Area3D = $'../../Vision/VisionArea'
@onready var vision_ray: RayCast3D = $'../../Vision/VisionRay'
signal PlayerDetected
func patrol(delta):
if can_patrol == true:
PathFollow.progress += move_speed * delta
else:
return
func set_markers():
var points = Path.curve.get_point_count()
for p in points:
var marker = marker_instance.instantiate()
add_child(marker)
var pointPos = Path.curve.get_point_position(p)
marker.position = pointPos
print('markers deployed')
func Enter():
print("Entering Idle State")
can_patrol = true
set_markers()
func Exit():
can_patrol = false
print("Exiting Idle State")
func Physics_Update(delta: float):
patrol(delta)
func _on_point_searcher_area_entered(area: Area3D) -> void:
if area.is_in_group("Stopping_Point"):
can_patrol = false
wait_time.start()
func _on_wait_time_timeout() -> void:
can_patrol = true
func _on_vision_timer_timeout() -> void:
var overlaps = vision_area.get_overlapping_bodies()
if overlaps.size() > 0:
for overlap in overlaps:
if overlap is Player:
var playerPos = overlap.global_transform.origin
vision_ray.look_at(playerPos, Vector3.UP)
vision_ray.force_raycast_update()
if vision_ray.is_colliding():
var collider = vision_ray.get_collider()
if collider is Player:
Transitioned.emit(self,"Chase")
emit_signal("PlayerDetected",collider)