From 462e966e6338311487e4c1fb77bc5925a41f203a Mon Sep 17 00:00:00 2001 From: Malcolm Nixon Date: Thu, 3 Mar 2022 17:11:53 -0500 Subject: [PATCH] Remove unnecessary getters and added safe update functions. Added collision layer and mask exported properties Added setget to radius to update the collision view in the editor --- addons/godot-xr-tools/assets/PlayerBody.gd | 52 ++++++++++++++++++---- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/addons/godot-xr-tools/assets/PlayerBody.gd b/addons/godot-xr-tools/assets/PlayerBody.gd index 753748ac..371b8c43 100644 --- a/addons/godot-xr-tools/assets/PlayerBody.gd +++ b/addons/godot-xr-tools/assets/PlayerBody.gd @@ -21,10 +21,10 @@ extends Node ## ## PlayerBody enabled flag -export var enabled := true setget set_enabled, get_enabled +export var enabled := true setget set_enabled ## Player radius -export var player_radius := 0.4 +export var player_radius := 0.4 setget set_player_radius ## Eyes forward offset from center of body in player_radius units export (float, 0.0, 1.0) var eye_forward_offset := 0.66 @@ -36,7 +36,7 @@ export var gravity := -9.8 export var push_rigid_bodies := true ## GroundPhysicsSettings to apply - can only be typed in Godot 4+ -export (Resource) var physics = null setget set_physics, get_physics +export (Resource) var physics = null setget set_physics ## Path to the ARVROrigin node export (NodePath) var origin = null @@ -44,6 +44,12 @@ export (NodePath) var origin = null ## Path to the ARVRCamera node export (NodePath) var camera = null +# Set our collision layer +export (int, LAYERS_3D_PHYSICS) var collision_layer = 1 << 19 setget set_collision_layer + +# Set our collision mask +export (int, LAYERS_3D_PHYSICS) var collision_mask = 1023 setget set_collision_mask + ## ARVROrigin node var origin_node: ARVROrigin = null @@ -133,9 +139,18 @@ func _ready(): _movement_providers = get_tree().get_nodes_in_group("movement_providers") _movement_providers.sort_custom(SortProviderByOrder, "sort_by_order") + # Propagate defaults + _update_enabled() + _update_player_radius() + _update_collision_layer() + _update_collision_mask() + func set_enabled(new_value): enabled = new_value + if is_inside_tree(): + _update_enabled() +func _update_enabled() -> void: # Update collision_shape if _collision_node: _collision_node.disabled = !enabled @@ -144,16 +159,37 @@ func set_enabled(new_value): if enabled: set_physics_process(true) -func get_enabled(): - return enabled +func set_player_radius(new_value: float) -> void: + player_radius = new_value + if is_inside_tree(): + _update_player_radius() + +func _update_player_radius() -> void: + if _collision_node and _collision_node.shape: + _collision_node.shape.radius = player_radius -func set_physics(new_value: Resource): +func set_physics(new_value: Resource) -> void: # Save the property physics = new_value default_physics = _guaranteed_physics() -func get_physics() -> Resource: - return physics +func set_collision_layer(new_layer: int) -> void: + collision_layer = new_layer + if is_inside_tree(): + _update_collision_layer() + +func _update_collision_layer() -> void: + if kinematic_node: + kinematic_node.collision_layer = collision_layer + +func set_collision_mask(new_mask: int) -> void: + collision_mask = new_mask + if is_inside_tree(): + _update_collision_mask() + +func _update_collision_mask() -> void: + if kinematic_node: + kinematic_node.collision_mask = collision_mask func _physics_process(delta): # Do not run physics if in the editor