updated detection of forbidden areas
This commit is contained in:
parent
c1a0d5672d
commit
88e184e52d
@ -5,6 +5,7 @@ export(NodePath) var _visibility_path: NodePath
|
||||
export(int) var _player_follow_pill_level = 3
|
||||
|
||||
var _visibility: Area
|
||||
var _playerRef
|
||||
|
||||
|
||||
func _ready():
|
||||
@ -15,10 +16,15 @@ func _ready():
|
||||
_visibility.connect("body_entered", self, "_on_body_entered_visibility")
|
||||
_visibility.connect("body_exited", self, "_on_body_exited_visibility")
|
||||
|
||||
# TODO: does this implementation have to be that way?
|
||||
for player in get_tree().get_nodes_in_group("Player"):
|
||||
_playerRef = player
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
# stop following player if pill level is high enough
|
||||
if current_target and Pills.get_round_level() > _player_follow_pill_level:
|
||||
# stop following player if pill level is high enough and player is not in an illegal area
|
||||
if current_target and Pills.get_round_level() > _player_follow_pill_level and _playerRef.Is_in_Illegal_Area() == false:
|
||||
Logger.info("player pill level ok and no illegal actions detected!")
|
||||
current_target = null
|
||||
|
||||
|
||||
@ -28,8 +34,10 @@ func _on_body_entered_visibility(body: PhysicsBody):
|
||||
if body.is_in_group("Player"):
|
||||
Logger.info("Seeing player!")
|
||||
|
||||
# TODO: check if player is in illegal area
|
||||
#var player = get_node("")
|
||||
# check if player is in illegal area
|
||||
if _playerRef.Is_in_Illegal_Area():
|
||||
Logger.info("player is in illegal area - following!")
|
||||
current_target = body.transform.origin
|
||||
|
||||
# If the player didn't take enough pills lately, they're suspicious -> Run towards them!
|
||||
if Pills.get_round_level() <= _player_follow_pill_level:
|
||||
|
@ -30,7 +30,7 @@ var _labelInteract: Label
|
||||
var _dir = Vector3()
|
||||
var _vel = Vector3()
|
||||
var _is_sprinting : bool
|
||||
var _is_in_illegal_area : bool
|
||||
var _illegal_areas : int
|
||||
var _prev_look
|
||||
|
||||
# TODO: move to global
|
||||
@ -177,7 +177,7 @@ func _input(event):
|
||||
func _on_area_entered (area: Area):
|
||||
if area.is_in_group("Enemy"):
|
||||
Logger.info("ermahgerd they touched :-o !")
|
||||
if _is_in_illegal_area: # or Pills.get_level() == 0: #< Pills.get_max() * 0.5:
|
||||
if _illegal_areas > 0: # or Pills.get_level() == 0: #< Pills.get_max() * 0.5:
|
||||
# TODO: check why this does not work as intended:
|
||||
#var player = AudioStreamPlayer3D.new()
|
||||
#var audio_file = "res://Resources/Audio/dino-eat.wav"
|
||||
@ -193,13 +193,13 @@ func _on_area_entered (area: Area):
|
||||
_reset_scene() # TODO: call per event -> also raise if Meldewesen is looking at player and pill level reaches treshold!
|
||||
elif area.is_in_group("Forbidden"):
|
||||
Logger.info("entering forbidden area!")
|
||||
_is_in_illegal_area = true
|
||||
_illegal_areas += 1
|
||||
|
||||
|
||||
func _on_area_exited (area: Area):
|
||||
if area.is_in_group("Forbidden"):
|
||||
Logger.info("leaving forbidden area!")
|
||||
_is_in_illegal_area = false
|
||||
_illegal_areas -= 1
|
||||
|
||||
|
||||
func _reset_scene ():
|
||||
@ -214,4 +214,5 @@ func _reset_scene ():
|
||||
|
||||
|
||||
func Is_in_Illegal_Area ():
|
||||
return _is_in_illegal_area
|
||||
#Logger.info("illegal areas: " + String(_illegal_areas))
|
||||
return _illegal_areas > 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user