I am trying to make a small demo for a simulation and I thought this part was going to be easy. Boy was I wrong and now I am totally stuck. Here is my problem.
I am trying to work with rotation and for this issue we will work with a 30 degree angle which is shown below:
The green ray is -15 degrees, red is 0 degrees and blue is +15 degrees for a total of 30 degrees.
Now I want to divide said 30 degrees into equalish parts so the first good number would be 10. meaning I can draw a ray every 3 degrees until I hit my maximum which in this case is +15 degrees. This can be seen below:
Looks good! There is a small amount of space that is off and if anyone knows why that is please let me know.
Now, I need a large amount of rays so we are going to go up by a factor of 10 and increase the number of divisions to 100 which can be seen below. Also I need to use imgur because there are only two pictures allowed here so please bear with me and thank you.
The first picture is with 100 chunks and as you can see the rays are all cast to the left. That is a problem.
The second picture is with the divisions increased to 1000. Even worse now is the fact that the got all the way around the object except for a 15 degree area.
Here is the snippet that is doing this.
if(testRotation)
{
//Sets the objects rotation to the starting rotation which is -15 degeres
this.transform.Rotate(this.transform.rotation.x, this.transform.rotation.y - 15.0f,
this.transform.rotation.z);
for (int i = 0; i <= 10; i++)
{
//Draws a ray at the current position and forwards relative to the objects transform
Debug.DrawRay(this.transform.position,
this.transform.forward * maxSightDistance, Color.cyan, 1000.0f);
//This advances the rotation by a factor of one chunk
//which in this case is 10 which seems to work
this.transform.Rotate(new Vector3(this.transform.rotation.x,
this.transform.rotation.y + (30/10), this.transform.rotation.z));
}
//This makes it so it doesn't run forever
testRotation = false;
}
The only places that change are in the for loop where the conditional is checked and also the second parameter of the Rotate function which adds to the current rotational value by “one chunk”.
For 100 chunks I modify the pieces to: for(int i = 0; i < 100; i++)
and this.transform.rotation.y + (30/100)
For 1000 chunks I modify the pieces to: for(int i = 0; i < 1000; i++)
and this.transform.rotation.y + (30/1000)
I am totally stuck and don’t know why it’s is doing what it’s doing. Also if you need something explained or clarified please let me know !