From d735e65032476967764dcec2015fc81bdef00574 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 10 Aug 2023 14:09:08 -0700 Subject: [PATCH] testing --- NewHorizons/Components/AddPhysics.cs | 29 ++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Components/AddPhysics.cs b/NewHorizons/Components/AddPhysics.cs index 9576e20b..963a5bef 100644 --- a/NewHorizons/Components/AddPhysics.cs +++ b/NewHorizons/Components/AddPhysics.cs @@ -1,6 +1,7 @@ using NewHorizons.Utility.OuterWilds; using System.Collections; using UnityEngine; +using UnityEngine.InputSystem; namespace NewHorizons.Components; @@ -19,11 +20,16 @@ public class AddPhysics : MonoBehaviour "If there's already good colliders on the detail, you can make this 0.")] public float Radius = 1f; + private OWRigidbody parentBody; + private OWRigidbody owRigidbody; + private IEnumerator Start() { yield return new WaitForSeconds(.1f); - var parentBody = GetComponentInParent(); + parentBody = GetComponentInParent(); + + // yield return new WaitUntil(() => Keyboard.current.lKey.isPressed); // hack: make all mesh colliders convex // triggers are already convex @@ -37,8 +43,10 @@ public class AddPhysics : MonoBehaviour bodyGo.transform.position = transform.position; bodyGo.transform.rotation = transform.rotation; - var owRigidbody = bodyGo.AddComponent(); + owRigidbody = bodyGo.AddComponent(); owRigidbody._simulateInSector = Sector; + // owRigidbody._autoGenerateCenterOfMass = false; + // owRigidbody._centerOfMass = owRigidbody.transform.InverseTransformPoint(parentBody.GetPosition()); bodyGo.layer = Layer.PhysicalDetector; bodyGo.tag = "DynamicPropDetector"; @@ -72,8 +80,7 @@ public class AddPhysics : MonoBehaviour transform.parent = bodyGo.transform; owRigidbody.SetMass(Mass); - owRigidbody.SetVelocity(parentBody.GetPointVelocity(transform.position)); - owRigidbody.SetAngularVelocity(parentBody.GetAngularVelocity()); + owRigidbody.SetVelocity(parentBody.GetPointVelocity(owRigidbody.GetWorldCenterOfMass())); // #536 - Physics objects in bramble dimensions not disabled on load // sectors wait 3 frames and then call OnSectorOccupantsUpdated @@ -82,6 +89,8 @@ public class AddPhysics : MonoBehaviour if (owRigidbody._simulateInSector != null) owRigidbody.OnSectorOccupantsUpdated(); + yield return new WaitUntil(() => Keyboard.current.kKey.isPressed); + Destroy(this); } @@ -89,4 +98,16 @@ public class AddPhysics : MonoBehaviour { Gizmos.DrawWireSphere(transform.position, Radius); } + + private void OnRenderObject() + { + Popcron.Gizmos.Sphere(transform.position, Radius); + Popcron.Gizmos.Line(transform.position, parentBody.GetPosition()); + Popcron.Gizmos.Line(transform.position, owRigidbody.GetWorldCenterOfMass()); + } + + private void FixedUpdate() + { + // owRigidbody.SetVelocity(parentBody.GetPointVelocity(owRigidbody.GetWorldCenterOfMass())); + } }