Prechádzať zdrojové kódy

Remotely playable version

- shows bounding boxes to scale in screen coordinates
- paddle usable via z coordinate
- ball resets automatically when lost
- select paddle automatically
Nick Steyer 2 rokov pred
rodič
commit
c573d63ed7

+ 8 - 9
Assembly-CSharp.csproj

@@ -11,8 +11,7 @@
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
     <ProductVersion>10.0.20506</ProductVersion>
     <SchemaVersion>2.0</SchemaVersion>
-    <RootNamespace>
-    </RootNamespace>
+    <RootNamespace></RootNamespace>
     <ProjectGuid>{4322513C-6AC2-9058-38C0-BCFE306751F6}</ProjectGuid>
     <OutputType>Library</OutputType>
     <AppDesignerFolder>Properties</AppDesignerFolder>
@@ -60,11 +59,6 @@
     <Analyzer Include="C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Microsoft\Visual Studio Tools for Unity\Analyzers\Microsoft.Unity.Analyzers.dll" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="Assets\Logging\DetectionFrameLogger.cs" />
-    <Compile Include="Assets\Logging\ILogger.cs" />
-    <Compile Include="Assets\ZED\Interfaces\IZEDManager.cs" />
-    <Compile Include="Assets\ZED\SDK\Helpers\Scripts\IZEDManager.cs" />
-    <Compile Include="Assets\ZED\SDK\Helpers\Scripts\LoggingZEDManager.cs" />
     <Compile Include="Assets\ZED\Tools\Mixed Reality Calibration\Scripts\ChooseTrackedObjectMenu.cs" />
     <Compile Include="Assets\Ball.cs" />
     <Compile Include="Assets\ZED\SDK\Helpers\Scripts\ObjectDetection\DetectedObject.cs" />
@@ -145,6 +139,7 @@
     <Compile Include="Assets\ZED\Tools\Mixed Reality Calibration\Scripts\TransformControl.cs" />
     <Compile Include="Assets\ZED\Tools\Mixed Reality Calibration\Scripts\ToggleButton.cs" />
     <Compile Include="Assets\ZED\SDK\Helpers\Scripts\Utilities\ExportNavMesh.cs" />
+    <Compile Include="Assets\ZED\SDK\Helpers\Scripts\LoggingZEDManager.cs" />
     <Compile Include="Assets\ZED\Examples\OpenCV ArUco Detection\Scripts\Core\MarkerObject_CreateObjectsAtMarkers.cs" />
     <Compile Include="Assets\ZED\SDK\Helpers\Scripts\SpatialMapping\ZEDMeshRenderer.cs" />
     <Compile Include="Assets\ZED\Tools\Mixed Reality Calibration\Scripts\CameraAnchor.cs" />
@@ -170,8 +165,10 @@
     <Compile Include="Assets\ZED\Tools\Mixed Reality Calibration\Scripts\RotateRing.cs" />
     <Compile Include="Assets\ZED\SDK\Helpers\Scripts\Lighting\ZEDLight.cs" />
     <Compile Include="Assets\ZED\SDK\Helpers\Scripts\Interactions\ZEDTransformController.cs" />
+    <Compile Include="Assets\Logging\ILogger.cs" />
     <Compile Include="Assets\ZED\Examples\OpenCV ArUco Detection\Scripts\Simple Placement\ScaleToMarkerSize.cs" />
     <Compile Include="Assets\ZED\Examples\Drone Shooter\Scripts\Simple\PlayerDamageReceiver.cs" />
+    <Compile Include="Assets\ZED\SDK\Helpers\Scripts\IZEDManager.cs" />
     <Compile Include="Assets\ZED\SDK\Helpers\Scripts\Interactions\ZEDControllerTracker.cs" />
     <Compile Include="Assets\ZED\SDK\Helpers\Scripts\Display\ZEDPointCloudManager.cs" />
     <Compile Include="Assets\ZED\Tools\Mixed Reality Calibration\Scripts\BellyMenu.cs" />
@@ -188,6 +185,7 @@
     <Compile Include="Assets\ZED\Tools\Mixed Reality Calibration\Scripts\SpotlightFollow.cs" />
     <Compile Include="Assets\ZED\SDK\NativeInterface\ZEDLayersManager.cs" />
     <Compile Include="Assets\ZED\SDK\Helpers\Scripts\Utilities\LayerHandler.cs" />
+    <Compile Include="Assets\Logging\DetectionFrameLogger.cs" />
     <Compile Include="Assets\ZED\SDK\Helpers\Scripts\Utilities\ZEDSupportFunctions.cs" />
     <Compile Include="Assets\ZED\SDK\Helpers\Scripts\Utilities\CappedStack.cs" />
     <Compile Include="Assets\ZED\Examples\Drone Shooter\Scripts\Simple\LaserShot_Player.cs" />
@@ -976,7 +974,8 @@
       <HintPath>Library\ScriptAssemblies\Unity.VisualScripting.State.dll</HintPath>
     </Reference>
   </ItemGroup>
-  <ItemGroup />
+  <ItemGroup>
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Target Name="GenerateTargetFrameworkMonikerAttribute" />
   <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
@@ -994,4 +993,4 @@
   <Target Name="AfterBuild">
   </Target>
   -->
-</Project>
+</Project>

+ 12 - 12
Assets/Logging/DetectionFrameLogger.cs

@@ -1,13 +1,13 @@
-using System;
+using System;
 using System.IO;
 using System.Text;
-using UnityEngine;
-
-namespace Assets.Logging
-{
-    internal class DetectionFrameLogger : ILogger<DetectionFrame>
-    {
-        public void Log(DetectionFrame frame)
+using UnityEngine;
+
+namespace Assets.Logging
+{
+    internal class DetectionFrameLogger : ILogger<DetectionFrame>
+    {
+        public void Log(DetectionFrame frame)
         {
             var builder = new StringBuilder();
             builder.AppendLine($"{DateTime.Now}: Detected {frame.objectCount} objects");
@@ -20,7 +20,7 @@ namespace Assets.Logging
                 builder.AppendLine($"{DateTime.Now}: Object {count} detected at ({position.x}|{position.y}|{position.z}). Type: {detectedObject.objectClass}");
             }
 
-            File.AppendAllText(@"C:\Users\nick.steyer\SmartStreetLight\log.txt", builder.ToString());
-        }
-    }
-}
+            File.AppendAllText(@"C:\Users\nick.steyer\SmartStreetLight\log.txt", builder.ToString());
+        }
+    }
+}

+ 2 - 3
Assets/Scenes/BoundingBoxes.unity

@@ -152,7 +152,6 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: 050df1fa7a5de6f40a3677d766ed3063, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
-  zedManager: {fileID: 0}
   startObjectDetectionAutomatically: 1
   boundingBoxPrefab: {fileID: 1438017172825460, guid: 2d803190bc4738d4daf5932468a5495e, type: 3}
   boxColors:
@@ -586,7 +585,7 @@ Transform:
   m_GameObject: {fileID: 844576506}
   m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
   m_LocalPosition: {x: 0, y: 0, z: -6}
-  m_LocalScale: {x: 23, y: 1, z: 1}
+  m_LocalScale: {x: 24, y: 1, z: 1}
   m_ConstrainProportionsScale: 0
   m_Children: []
   m_Father: {fileID: 0}
@@ -923,7 +922,7 @@ Transform:
   m_GameObject: {fileID: 1310445729}
   m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
   m_LocalPosition: {x: 0, y: 0, z: 6}
-  m_LocalScale: {x: 23, y: 1, z: 1}
+  m_LocalScale: {x: 24, y: 1, z: 1}
   m_ConstrainProportionsScale: 0
   m_Children: []
   m_Father: {fileID: 0}

+ 0 - 267
Assets/Scenes/SampleScene.unity

@@ -1,267 +0,0 @@
-%YAML 1.1
-%TAG !u! tag:unity3d.com,2011:
---- !u!29 &1
-OcclusionCullingSettings:
-  m_ObjectHideFlags: 0
-  serializedVersion: 2
-  m_OcclusionBakeSettings:
-    smallestOccluder: 5
-    smallestHole: 0.25
-    backfaceThreshold: 100
-  m_SceneGUID: 00000000000000000000000000000000
-  m_OcclusionCullingData: {fileID: 0}
---- !u!104 &2
-RenderSettings:
-  m_ObjectHideFlags: 0
-  serializedVersion: 9
-  m_Fog: 0
-  m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
-  m_FogMode: 3
-  m_FogDensity: 0.01
-  m_LinearFogStart: 0
-  m_LinearFogEnd: 300
-  m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
-  m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
-  m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
-  m_AmbientIntensity: 1
-  m_AmbientMode: 0
-  m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
-  m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
-  m_HaloStrength: 0.5
-  m_FlareStrength: 1
-  m_FlareFadeSpeed: 3
-  m_HaloTexture: {fileID: 0}
-  m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
-  m_DefaultReflectionMode: 0
-  m_DefaultReflectionResolution: 128
-  m_ReflectionBounces: 1
-  m_ReflectionIntensity: 1
-  m_CustomReflection: {fileID: 0}
-  m_Sun: {fileID: 705507994}
-  m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
-  m_UseRadianceAmbientProbe: 0
---- !u!157 &3
-LightmapSettings:
-  m_ObjectHideFlags: 0
-  serializedVersion: 12
-  m_GIWorkflowMode: 1
-  m_GISettings:
-    serializedVersion: 2
-    m_BounceScale: 1
-    m_IndirectOutputScale: 1
-    m_AlbedoBoost: 1
-    m_EnvironmentLightingMode: 0
-    m_EnableBakedLightmaps: 1
-    m_EnableRealtimeLightmaps: 0
-  m_LightmapEditorSettings:
-    serializedVersion: 12
-    m_Resolution: 2
-    m_BakeResolution: 40
-    m_AtlasSize: 1024
-    m_AO: 0
-    m_AOMaxDistance: 1
-    m_CompAOExponent: 1
-    m_CompAOExponentDirect: 0
-    m_ExtractAmbientOcclusion: 0
-    m_Padding: 2
-    m_LightmapParameters: {fileID: 0}
-    m_LightmapsBakeMode: 1
-    m_TextureCompression: 1
-    m_FinalGather: 0
-    m_FinalGatherFiltering: 1
-    m_FinalGatherRayCount: 256
-    m_ReflectionCompression: 2
-    m_MixedBakeMode: 2
-    m_BakeBackend: 1
-    m_PVRSampling: 1
-    m_PVRDirectSampleCount: 32
-    m_PVRSampleCount: 500
-    m_PVRBounces: 2
-    m_PVREnvironmentSampleCount: 500
-    m_PVREnvironmentReferencePointCount: 2048
-    m_PVRFilteringMode: 2
-    m_PVRDenoiserTypeDirect: 0
-    m_PVRDenoiserTypeIndirect: 0
-    m_PVRDenoiserTypeAO: 0
-    m_PVRFilterTypeDirect: 0
-    m_PVRFilterTypeIndirect: 0
-    m_PVRFilterTypeAO: 0
-    m_PVREnvironmentMIS: 0
-    m_PVRCulling: 1
-    m_PVRFilteringGaussRadiusDirect: 1
-    m_PVRFilteringGaussRadiusIndirect: 5
-    m_PVRFilteringGaussRadiusAO: 2
-    m_PVRFilteringAtrousPositionSigmaDirect: 0.5
-    m_PVRFilteringAtrousPositionSigmaIndirect: 2
-    m_PVRFilteringAtrousPositionSigmaAO: 1
-    m_ExportTrainingData: 0
-    m_TrainingDataDestination: TrainingData
-    m_LightProbeSampleCountMultiplier: 4
-  m_LightingDataAsset: {fileID: 0}
-  m_LightingSettings: {fileID: 0}
---- !u!196 &4
-NavMeshSettings:
-  serializedVersion: 2
-  m_ObjectHideFlags: 0
-  m_BuildSettings:
-    serializedVersion: 2
-    agentTypeID: 0
-    agentRadius: 0.5
-    agentHeight: 2
-    agentSlope: 45
-    agentClimb: 0.4
-    ledgeDropHeight: 0
-    maxJumpAcrossDistance: 0
-    minRegionArea: 2
-    manualCellSize: 0
-    cellSize: 0.16666667
-    manualTileSize: 0
-    tileSize: 256
-    accuratePlacement: 0
-    debug:
-      m_Flags: 0
-  m_NavMeshData: {fileID: 0}
---- !u!1 &705507993
-GameObject:
-  m_ObjectHideFlags: 0
-  m_CorrespondingSourceObject: {fileID: 0}
-  m_PrefabInternal: {fileID: 0}
-  serializedVersion: 6
-  m_Component:
-  - component: {fileID: 705507995}
-  - component: {fileID: 705507994}
-  m_Layer: 0
-  m_Name: Directional Light
-  m_TagString: Untagged
-  m_Icon: {fileID: 0}
-  m_NavMeshLayer: 0
-  m_StaticEditorFlags: 0
-  m_IsActive: 1
---- !u!108 &705507994
-Light:
-  m_ObjectHideFlags: 0
-  m_CorrespondingSourceObject: {fileID: 0}
-  m_PrefabInternal: {fileID: 0}
-  m_GameObject: {fileID: 705507993}
-  m_Enabled: 1
-  serializedVersion: 8
-  m_Type: 1
-  m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
-  m_Intensity: 1
-  m_Range: 10
-  m_SpotAngle: 30
-  m_CookieSize: 10
-  m_Shadows:
-    m_Type: 2
-    m_Resolution: -1
-    m_CustomResolution: -1
-    m_Strength: 1
-    m_Bias: 0.05
-    m_NormalBias: 0.4
-    m_NearPlane: 0.2
-  m_Cookie: {fileID: 0}
-  m_DrawHalo: 0
-  m_Flare: {fileID: 0}
-  m_RenderMode: 0
-  m_CullingMask:
-    serializedVersion: 2
-    m_Bits: 4294967295
-  m_Lightmapping: 1
-  m_LightShadowCasterMode: 0
-  m_AreaSize: {x: 1, y: 1}
-  m_BounceIntensity: 1
-  m_ColorTemperature: 6570
-  m_UseColorTemperature: 0
-  m_ShadowRadius: 0
-  m_ShadowAngle: 0
---- !u!4 &705507995
-Transform:
-  m_ObjectHideFlags: 0
-  m_CorrespondingSourceObject: {fileID: 0}
-  m_PrefabInternal: {fileID: 0}
-  m_GameObject: {fileID: 705507993}
-  m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
-  m_LocalPosition: {x: 0, y: 3, z: 0}
-  m_LocalScale: {x: 1, y: 1, z: 1}
-  m_Children: []
-  m_Father: {fileID: 0}
-  m_RootOrder: 1
-  m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
---- !u!1 &963194225
-GameObject:
-  m_ObjectHideFlags: 0
-  m_CorrespondingSourceObject: {fileID: 0}
-  m_PrefabInternal: {fileID: 0}
-  serializedVersion: 6
-  m_Component:
-  - component: {fileID: 963194228}
-  - component: {fileID: 963194227}
-  - component: {fileID: 963194226}
-  m_Layer: 0
-  m_Name: Main Camera
-  m_TagString: MainCamera
-  m_Icon: {fileID: 0}
-  m_NavMeshLayer: 0
-  m_StaticEditorFlags: 0
-  m_IsActive: 1
---- !u!81 &963194226
-AudioListener:
-  m_ObjectHideFlags: 0
-  m_CorrespondingSourceObject: {fileID: 0}
-  m_PrefabInternal: {fileID: 0}
-  m_GameObject: {fileID: 963194225}
-  m_Enabled: 1
---- !u!20 &963194227
-Camera:
-  m_ObjectHideFlags: 0
-  m_CorrespondingSourceObject: {fileID: 0}
-  m_PrefabInternal: {fileID: 0}
-  m_GameObject: {fileID: 963194225}
-  m_Enabled: 1
-  serializedVersion: 2
-  m_ClearFlags: 1
-  m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
-  m_projectionMatrixMode: 1
-  m_SensorSize: {x: 36, y: 24}
-  m_LensShift: {x: 0, y: 0}
-  m_GateFitMode: 2
-  m_FocalLength: 50
-  m_NormalizedViewPortRect:
-    serializedVersion: 2
-    x: 0
-    y: 0
-    width: 1
-    height: 1
-  near clip plane: 0.3
-  far clip plane: 1000
-  field of view: 60
-  orthographic: 0
-  orthographic size: 5
-  m_Depth: -1
-  m_CullingMask:
-    serializedVersion: 2
-    m_Bits: 4294967295
-  m_RenderingPath: -1
-  m_TargetTexture: {fileID: 0}
-  m_TargetDisplay: 0
-  m_TargetEye: 3
-  m_HDR: 1
-  m_AllowMSAA: 1
-  m_AllowDynamicResolution: 0
-  m_ForceIntoRT: 0
-  m_OcclusionCulling: 1
-  m_StereoConvergence: 10
-  m_StereoSeparation: 0.022
---- !u!4 &963194228
-Transform:
-  m_ObjectHideFlags: 0
-  m_CorrespondingSourceObject: {fileID: 0}
-  m_PrefabInternal: {fileID: 0}
-  m_GameObject: {fileID: 963194225}
-  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
-  m_LocalPosition: {x: 0, y: 1, z: -10}
-  m_LocalScale: {x: 1, y: 1, z: 1}
-  m_Children: []
-  m_Father: {fileID: 0}
-  m_RootOrder: 0
-  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

+ 63 - 18
Assets/ZED/Examples/Object Detection/Scripts/ZED3DObjectVisualizer.cs

@@ -143,13 +143,14 @@ public class ZED3DObjectVisualizer : MonoBehaviour
 
     private void Awake()
     {
-        zedManagerLazy = new(new LoggingZEDManager(FindObjectOfType<ZEDManager>(), new DetectionFrameLogger()));
+        //zedManagerLazy = new(new LoggingZEDManager(FindObjectOfType<ZEDManager>(), new DetectionFrameLogger()));
+        zedManagerLazy = new(() => FindObjectOfType<ZEDManager>());
     }
 
     // Use this for initialization
     void Start()
     {
-        ZedManager.OnObjectDetection += Visualize3DBoundingBoxes;
+        ZedManager.OnObjectDetection += ZedManager_OnObjectDetection;
         ZedManager.OnZEDReady += OnZEDReady;
 
         if (ZedManager.EstimateInitialPosition == false && transformBoxToTouchFloor == true)
@@ -159,6 +160,31 @@ public class ZED3DObjectVisualizer : MonoBehaviour
         }
     }
 
+    private void ZedManager_OnObjectDetection(DetectionFrame objFrame)
+    {
+        Visualize3DBoundingBoxes(objFrame);
+        UpdateMinMaxCoordinates(objFrame);
+    }
+
+    private void UpdateMinMaxCoordinates(DetectionFrame objFrame)
+    {
+        List<DetectedObject> newobjects = objFrame.GetFilteredObjectList(showONTracked, showSEARCHINGTracked, showOFFTracked);
+        foreach (var detectedObject in newobjects)
+        {
+            Bounds objbounds = detectedObject.Get3DWorldBounds();
+            if (objbounds.size.x < minimumWidthToDisplay || objbounds.size == Vector3.zero) { }
+            {
+                Vector3 obj_position = detectedObject.Get3DWorldPosition();
+                minX = Math.Min(minX, obj_position.x);
+                maxX = Math.Max(maxX, obj_position.x);
+                minY = Math.Min(minY, obj_position.y);
+                maxY = Math.Max(maxY, obj_position.y);
+                minZ = Math.Min(minZ, obj_position.z);
+                maxZ = Math.Max(maxZ, obj_position.z);
+            }
+        }
+    }
+
     private void OnZEDReady()
     {
         if (startObjectDetectionAutomatically && !ZedManager.IsObjectDetectionRunning)
@@ -167,6 +193,12 @@ public class ZED3DObjectVisualizer : MonoBehaviour
         }
     }
 
+    float maxX = 0.9971107f;
+    float minX = -0.7968294f;
+    float maxY = int.MinValue;
+    float minY = int.MaxValue;
+    float maxZ = 2.373606f;
+    float minZ = 0.4380694f;
 
     /// <summary>
     /// Given a frame of object detections, positions a GameObject to represent every visible object
@@ -181,19 +213,17 @@ public class ZED3DObjectVisualizer : MonoBehaviour
 
         List<DetectedObject> newobjects = dframe.GetFilteredObjectList(showONTracked, showSEARCHINGTracked, showOFFTracked);
 
-        if (newobjects.Any())
+        var ball = GameObject.Find("Sphere").GetComponent<Ball>();
+
+        if (ball.transform.position.x > -15 && ball.transform.position.x < 15 && newobjects.Any())
         {
-            if (newobjects.Count >= 2)
+            if (newobjects.Count >= 2 && !ball.IsInUse)
             {
-                var ball = GameObject.Find("Sphere").GetComponent<Ball>();
-                if (!ball.IsInUse)
-                {
-                    ball.Kickoff();
-                }
+                ball.Kickoff();
             }
 
             int count = 1;
-            foreach (var dobj in newobjects.Take(2))
+            foreach (var dobj in newobjects.OrderByDescending(i => i.Get3DWorldPosition().x).Take(2))
             {
                 GameObject bump = GameObject.Find($"Bump{count}");
                 Bounds objbounds = dobj.Get3DWorldBounds();
@@ -210,22 +240,38 @@ public class ZED3DObjectVisualizer : MonoBehaviour
                     Vector3 obj_position = dobj.Get3DWorldPosition();
 
                     Debug.Log($"count: {count}; X: {obj_position.x}; Y: {obj_position.y}; Z: {obj_position.z};");
+                    Debug.Log($"x: ({minX}|{maxX}), y: ({minY}|{maxY}), z: ({minZ}|{maxZ}), ");
 
                     if (!ZEDSupportFunctions.IsVector3NaN(obj_position))
                     {
                         bbox.transform.position = obj_position;
-                        if (obj_position.z > 3 && obj_position.z < 4)
-                        {
-                            var scale = obj_position.z - 3;
-                            var newZ = scale * 8 - 4;
-                            bump.transform.position = new Vector3(bump.transform.position.x, bump.transform.position.y, newZ);
-                        }
+
                         if (floorBBoxPosition)
                         {
                             bbox.transform.position = new Vector3(bbox.transform.position.x, 0, bbox.transform.position.z);
                         }
 
+                        var x = bbox.transform.position.x;
+
+                        var totalDistance = maxX - minX;
+                        var distanceFromStart = x - minX;
+                        var ratio = distanceFromStart / totalDistance;
+                        var newX = -12 + ratio * 24;
+
+                        var z = bbox.transform.position.z;
+
+                        totalDistance = maxZ - minZ;
+                        distanceFromStart = z - minZ;
+                        ratio = distanceFromStart / totalDistance;
+                        var newZ = -6 + ratio * 12;
+
+                        bbox.transform.position = new Vector3(newX, 0, newZ);
                         bbox.transform.rotation = dobj.Get3DWorldRotation(boxesFaceCamera); //Rotate them.
+
+                        if (bbox.transform.position.z > -5 && bbox.transform.position.z < 5)
+                        {
+                            bump.transform.position = new Vector3(bump.transform.position.x, bump.transform.position.y, bbox.transform.position.z);
+                        }
                     }
 
                     //Transform the box if desired.
@@ -274,7 +320,6 @@ public class ZED3DObjectVisualizer : MonoBehaviour
         }
         else
         {
-            var ball = GameObject.Find("Sphere").GetComponent<Ball>();
             ball.Recenter();
         }
     }
@@ -395,7 +440,7 @@ public class ZED3DObjectVisualizer : MonoBehaviour
     {
         if (ZedManager != null)
         {
-            ZedManager.OnObjectDetection -= Visualize3DBoundingBoxes;
+            ZedManager.OnObjectDetection -= ZedManager_OnObjectDetection;
             ZedManager.OnZEDReady -= OnZEDReady;
         }
     }