Added path dump for debug raycaster

This commit is contained in:
Ben C 2022-02-25 07:26:02 -08:00 committed by GitHub
parent 08c9afd988
commit 3cbc823b88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -1,4 +1,5 @@
using NewHorizons.Builder.Body;
using NewHorizons;
using NewHorizons.Builder.Body;
using System;
using System.Collections.Generic;
using System.Linq;
@ -21,7 +22,7 @@ namespace NewHorizons.Utility
private void Update()
{
if (Keyboard.current != null && Keyboard.current[Key.P].wasReleasedThisFrame)
if (Main.Debug && Keyboard.current != null && Keyboard.current[Key.P].wasReleasedThisFrame)
{
// Raycast
_rb.DisableCollisionDetection();
@ -31,7 +32,7 @@ namespace NewHorizons.Utility
if (Physics.Raycast(origin, direction, out RaycastHit hitInfo, 100f, layerMask))
{
var pos = hitInfo.transform.InverseTransformPoint(hitInfo.point);
Logger.Log($"Raycast hit {{\"x\": {pos.x}, \"y\": {pos.y}, \"z\": {pos.z}}} on [{hitInfo.transform.gameObject.name}]");
Logger.Log($"Raycast hit {{\"x\": {pos.x}, \"y\": {pos.y}, \"z\": {pos.z}}} on [{hitInfo.transform.gameObject.name}] at [{GetPath(hitInfo.transform.gameObject)}]");
}
_rb.EnableCollisionDetection();
}

View File

@ -172,5 +172,16 @@ namespace NewHorizons.Utility
}
return children;
}
public static string GetPath(GameObject obj)
{
string path = "/" + obj.name;
while (obj.transform.parent != null)
{
obj = obj.transform.parent.gameObject;
path = "/" + obj.name + path;
}
return path;
}
}
}