Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | potatobanana |
for some reason my mob sight only become true when my player at top him and false when have something in between player and mob. if go to left/right/bottom mob, i did’t get any print , but if put something in between i will get false print. did i do right?
mob code
onready var player = get_parent().get_node("player")
var player_in_range
var player_in_sight
func _physics_process(delta: float) -> void:
sight_update()
func _on_sight_body_entered(body: Node) -> void:
if body == player:
player_in_range = true
print(self.name," player in range ", player_in_range)
func _on_sight_body_exited(body: Node) -> void:
if body == player:
player_in_range = false
print(self.name ," player out of range ", player_in_range)
func sight_update():
if player_in_range == true:
var space_state = get_world_2d().direct_space_state
var sight_check = space_state.intersect_ray(position, player.position, [self], collision_mask)
if sight_check:
if sight_check.collider.name == "player":
player_in_sight = true
$icon.modulate = ColorN("black",1)
print(self.name," player in sight = ", player_in_sight, " = ",sight_check.position)
else:
player_in_sight = false
$icon.modulate = ColorN("crimson",1)
print(self.name," player not in sight = ", player_in_sight, " = ",sight_check.position)
map node