- Home /
Rotating guiTexture around a point in circle
Not knowing where to turn, i decide to post a question here
I got an empty gameObject where is located at (0.5, 0.5, 0), this gameObject also have a script, which create a random number of 2d texture with empty gameOjbject childs, then by the following code i set them one equidistant from another:
for (var i : int = 0; i < transform.childCount; i++){
transform.GetChild(i).localPosition = Vector3((xActivePositions[i]) * 0.2 * ringID, (yActivePositions[i]) * 0.2 * ringID, 0);
}
Where ringID is the radius and the array used are predefinited positions around a circle for example with 4 texture the arrays will be:
for the x [0f, -1f, 0f, 1f];
for the y [1f, 0f, -1f, 0f];
with 5 instead:
for the x [0, -0.95, -0.58, 0.58, 0.95];
for the y [1, 0.3, -0.8, -0.8, 0.3];
I achieve to set texture position around the point correctly but for the gui coordinates system what i create is not a circle but an oval deformed to fit the screen
What i want is to create a perfect circle in the middle of the screen, so that it fit a 1/3 of vertical space Then i start to modify randomly the code abowe, its seems that i obtain a circle dividing the y obtained by 2 So i obtained a circle, but i have to rotate texture around the center, i use this code:
function rotate(degrees : float, duration : float, anticlockwise : boolean){
if (busy) return;
busy = true;
var startTime : float = Time.time;
var startY : float = transform.rotation.eulerAngles.z;
var rotating : float = 0;
while (rotating < 10){
var t : float = (Time.time - startTime) / duration;
rotating += t;
if (anticlockwise) transform.rotation = Quaternion.Euler(0, 0, Mathf.SmoothStep(startY, startY + degrees, t));
else transform.rotation = Quaternion.Euler(0, 0, startY - Mathf.SmoothStep(0, degrees, t));
yield WaitForSeconds(0.0001);}
} busy = false;
This code works for me but:
-When my gui is setted as oval, the texture will rotate perfectly but i want to rotate around a circle
-When i adjust the code to make a circle, when i rotate, the circle will deform assuming a strange shape, only on 360 degree the texture are posed like a circle
Dividing the y position by 2 in the for circle i obtain a circle-like
So i try the rotate method, since there are 5 elements i'll call it with 72 degrees, clockwise but i'll obtain this deformation:
Really don't know what the heck happend, it will return to a circle only rotating 360 degrees Don't know if its related but the texture use this code to adjust fot the screen:
guiTexture.pixelInset = new Rect(- Screen.width / 16, - Screen.width / 16, Screen.width / 8, Screen.width / 8);
How can i rotate the texture around the point moving in circle properly?
I did my best to explain myself, sorry for my english too
Your answer
Follow this Question
Related Questions
GUIUtiliy.RotateAroundPivot() doesn't work 0 Answers
Rotate Texture 1 Answer
Create 3D GUI Button? 2 Answers
Size GUiLayout 2 Answers
How to plot velocity of vehicle wheel collider on realtime graph 0 Answers