Changing bridge zindex and body set layer and mask from bridge process function to each bridge area on_body_entered and on_body_exited. This change optimize code avoiding to set zindex of bridge and body layers and mask each frame. The script bridge is not necessary anymore.

This commit is contained in:
2025-06-21 21:11:11 -03:00
parent 724df1b070
commit 2490ca1e37
5 changed files with 29 additions and 80 deletions

View File

@@ -1,25 +1,22 @@
extends Area2D
class_name BridgeArea
var character_body: Node2D = null
var is_character_on_bridge: bool = false
func _on_body_entered(_body: Node2D) -> void:
#_body.update_collision_layer_mask("in")
self._set_character_body_on_bridge(_body, true)
if _body is BaseCharacter:
_body.set_collision_layer_value(8, false)
_body.set_collision_mask_value(8, false)
_body.set_collision_layer_value(1, false)
_body.set_collision_mask_value(1, false)
_body.set_collision_layer_value(2, true)
_body.set_collision_mask_value(2, true)
print("entering on bridge")
func _on_body_exited(_body: Node2D) -> void:
#_body.update_collision_layer_mask("out")
self._set_character_body_on_bridge(_body, false)
func _set_character_body_on_bridge(_body: Node2D, _state: bool) -> void:
if _body is BaseCharacter:
self.character_body = _body
self.is_character_on_bridge = _state
print("on bridge: " + str(_state))
func get_character_body_on_bridge() -> bool:
return self.is_character_on_bridge
func get_body() -> Node2D:
return self.character_body
_body.set_collision_layer_value(8, true)
_body.set_collision_mask_value(8, true)
_body.set_collision_layer_value(1, true)
_body.set_collision_mask_value(1, true)
_body.set_collision_layer_value(2, false)
_body.set_collision_mask_value(2, false)
print("exiting on bridge")