add debug collision shape
This commit is contained in:
59
scripts/debug/debug_collision_shapes.gd
Normal file
59
scripts/debug/debug_collision_shapes.gd
Normal file
@@ -0,0 +1,59 @@
|
||||
class_name DebugCollisionShapes
|
||||
extends RefCounted
|
||||
|
||||
var _mesh_nodes: Array[MeshInstance3D] = []
|
||||
|
||||
|
||||
func init(children: Array[Node], parent: Node, material: Material) -> void:
|
||||
for child in children:
|
||||
if child is not CollisionShape3D:
|
||||
continue
|
||||
var shape_node: CollisionShape3D = child as CollisionShape3D
|
||||
if shape_node.shape == null:
|
||||
continue
|
||||
|
||||
var mesh_node := MeshInstance3D.new()
|
||||
if shape_node.shape is BoxShape3D:
|
||||
var shape := shape_node.shape as BoxShape3D
|
||||
var mesh := BoxMesh.new()
|
||||
mesh.size = shape.size
|
||||
mesh_node.mesh = mesh
|
||||
if shape_node.shape is CapsuleShape3D:
|
||||
var shape := shape_node.shape as CapsuleShape3D
|
||||
var mesh := CapsuleMesh.new()
|
||||
mesh.radius = shape.radius
|
||||
mesh.height = shape.height
|
||||
mesh.radial_segments = 8
|
||||
mesh.rings = 1
|
||||
mesh_node.mesh = mesh
|
||||
if shape_node.shape is SphereShape3D:
|
||||
var shape := shape_node.shape as SphereShape3D
|
||||
var mesh := SphereMesh.new()
|
||||
mesh.radius = shape.radius
|
||||
mesh.height = shape.radius * 2
|
||||
mesh.radial_segments = 8
|
||||
mesh.rings = 4
|
||||
mesh_node.mesh = mesh
|
||||
if shape_node.shape is CylinderShape3D:
|
||||
var shape := shape_node.shape as CylinderShape3D
|
||||
var mesh := CylinderMesh.new()
|
||||
mesh.top_radius = shape.radius
|
||||
mesh.bottom_radius = shape.radius
|
||||
mesh.height = shape.height
|
||||
mesh.radial_segments = 8
|
||||
mesh.rings = 0
|
||||
mesh_node.mesh = mesh
|
||||
|
||||
mesh_node.material_override = material
|
||||
mesh_node.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
|
||||
mesh_node.visible = false
|
||||
parent.add_child(mesh_node)
|
||||
mesh_node.global_transform = (child as Node3D).global_transform
|
||||
_mesh_nodes.append(mesh_node)
|
||||
|
||||
Debugger.mode_changed.connect(_on_debugger_mode_changed)
|
||||
|
||||
|
||||
func _on_debugger_mode_changed(mode: Debugger.Mode) -> void:
|
||||
for mesh_node in _mesh_nodes:
|
||||
mesh_node.visible = mode == Debugger.Mode.FULL
|
||||
@@ -2,16 +2,19 @@ class_name Player
|
||||
extends CharacterBody3D
|
||||
|
||||
@export var _respawn_height: float = -5
|
||||
@export var _collision_debug_material: Material
|
||||
|
||||
var movement: PlayerMovement = PlayerMovement.new()
|
||||
var aiming: PlayerAiming = PlayerAiming.new()
|
||||
|
||||
var _respawn_point: Vector3
|
||||
var _debug_collision_shapes := DebugCollisionShapes.new()
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_respawn_point = global_position
|
||||
Referencer.player = self
|
||||
_debug_collision_shapes.init(get_children(), self, _collision_debug_material)
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
|
||||
Reference in New Issue
Block a user