Capsule Collider Radius

Is the reason we divide viewingRadius by 2 for the capsule collider's radius because the enemy object is scaled to (2,2,2)?

Referring to this line:

col.radius = viewingRadius / 2;
  • Jonathan Gonzalez(jgonzalez) replied

    Honestly it's been a while since I looked at the code so I can't say for sure, but I believe that was just done to decrease the detection trigger "range". 

    The viewingRadius used in the video was set to 8, which would result in a fairly large collider making it much easier for the enemy characters to spot the player. Since I'm manually adjusting the collider radius the scale of the player doesn't really matter here.

     Note that you don't need to include the collider radius via script, this can all be done manually. I just wanted a way to dynamically resize the collider anytime I changed the viewingRadius.

  • Nicholas Yang(nyanginator) replied

    Here's an example where viewingRadius is manually to 8:

    • With scale being (1,1,1), the viewingRadius/2 makes the sphere collider half size.
    • With scale being (2,2,2), viewingRadius/2 makes it fit exactly right.

    So my theory is that the viewingRadius is affected by scaling up to (2,2,2).


    Setting the scale to (4,4,4), we now see the radius of the sphere collider seems to match viewingRadius*4/2, which is 16.


  • Jonathan Gonzalez(jgonzalez) replied

    Ah yes you're right, it's been a while since I last looked at that code. Makes sense why I did it that way, I just couldn't remember why.