Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Sphere Collider reacts to late as trigger

Discussion in 'Scripting' started by SebWei, Sep 8, 2020.

  1. SebWei

    SebWei

    Joined:
    Mar 19, 2020
    Posts:
    7
    Hello everyone!
    The following snipped should check if an endpoint of a machine is inside its workspace. Therefor I used a sphere collider and check the bounds as shown.
    It looks like the trigger reacts way to late. Let's say the radius of my collider is 2 it starts the debuglog "Outside..." only if the target is about 2.5 units outside the center of the collider.
    I don't get my head around this issue.

    Code (CSharp):
    1. if (Workspace.bounds.Contains(Target.transform.position))
    2.         {
    3.             Debug.Log("Inside Workspace");
    4.         }
    5.         else
    6.         {
    7.             Debug.Log("Outside Workspace");
    8.         }
     
  2. SebWei

    SebWei

    Joined:
    Mar 19, 2020
    Posts:
    7
    Okay... I found it. Bounds generates a Cube, not a Sphere. So... This is the wrong way to check a spherical workspace.
    Code (CSharp):
    1. Distance = Vector3.Distance(A1.transform.position, Target.transform.position); // Is the endeffector inside its Workspace
    2.         if (Distance < 1.8f)
    3.         {
    4.             Debug.Log("Inside Workspace");
    5.         }
    6.         else
    7.         {
    8.             Debug.Log("Outside Workspace");
    9.         }
    This works perfectly fine
     
    Last edited: Sep 8, 2020