Comments and answers for "How can calculate the drawn circle range ?"
http://answers.unity.com/questions/1389864/how-can-calculate-the-drawn-circle-range.html
The latest comments and answers for the question "How can calculate the drawn circle range ?"Comment by Chocolade on Chocolade's answer
http://answers.unity.com/comments/1389906/view.html
Thank you.
So i did:
rangeSqr = drawcircle.xradius * drawcircle.xradius;
But still the condition is wrong yet.
So what the condition should be like now ?
(I changed it all the DrawCircle script is now only on the Turret so there is a drawn circle around the Turret. Should i add the DrawCircle script also to the Enemy GameObject that move to the Turret ?)
And then how do i check if both circles overlap ?
And last thing what should i change in the DrawCircle script , You asked why i'm using different radii for x and z. I don't want to use ellipses only circles. So what should i change in the DrawCircle script ? line.SetPosition(i, new Vector3(x, 0, z)); Should i use only x not z ?Sun, 06 Aug 2017 06:40:29 GMTChocoladeComment by Bunny83 on Bunny83's answer
http://answers.unity.com/comments/1389879/view.html
So here's an example for a localspace ellipse:
Vector3 dir = transform.position - target.transform.position;
Vector3 localDir = target.transform.InverseTransformDirection(dir);
localDir = localDir.normalized;
Vector3 localRadius = Vector3.Scale(localDir, new Vector3(drawcircle.xradius, 0, drawcircle.yradius));
Vector3 worldRadius = target.transform.TransformDirection(localRadius);
if (dir.sqrMagnitude < worldRadius.sqrMagnitude)
// ...
Note: if you use a worldspace linerenderer (or a localspace renderer that isn't rotated) you can remove the InverseTransformDirection and the TransformDirection
Vector3 dir = transform.position - target.transform.position;
Vector3 worldRadius = Vector3.Scale(dir.normalized, new Vector3(drawcircle.xradius, 0, drawcircle.yradius));
if (dir.sqrMagnitude < worldRadius.sqrMagnitude)
// ...Sun, 06 Aug 2017 03:44:21 GMTBunny83Answer by Bunny83
http://answers.unity.com/answers/1389875/view.html
Here'
rangeSqr = drawcircle.xradius * 2;
you don't calculate the square of the radius but you multiply it by 2. So a radius of 5 would yield a value of 10 (5*2) instead of 25 (5*5).
Why exactly are you using two different radii for x and z ? If the two are not the same the result would be an ellipse instead of a circle. Many logical deductions won't work with an ellipse that does work with circles.
So you should do:
rangeSqr = drawcircle.xradius * drawcircle.xradius;
Note that you only check the center of the object. So the object is only inside when it's pivot enters the range. If the object is large the actual mesh might already overlap with your range but as long as the center isn't inside the range the object will still be considered outside. A common solution is to give both a circular range. You can simply add the two radii before you square it. This way your condition is only true if the two circles overlap.
ps:
If you want to be able to use an ellipse it gets more complicated as the radius depends on the orientation of the object. If your line renderer uses localspace positions the distance vector need to be transformed into the localspace of your linerenderer. The direction vector would be normalized and each component would be multiplied by the corresponding radius. Then you can calculate the squared length / magnitude of that vector. If both objects may use an ellipse each has to use it's own localspace to get the proper radius vector. Again you can simply add the two radius vectors before you get the square length in order to add their radii.Sun, 06 Aug 2017 03:15:18 GMTBunny83