- Home /
Rotate around Pivot.
A newbie here. What exactly am I trying to do is, rotate the cubes when I press the circle in the center. The first position of the cubes will be like in the figure one and when the circle is pressed then the cubes rotate with pivot point as the center of the circle. The cubes are just for informative purpose only, when the artist comes it will change to insects, that is why the 'cube A' in the second figure is lying down! (And also the cubes are individual there will be many other cubes and circles and also blank spaces in the grid ). Can any please guide me how to do this?
As the first step I'm just trying to rotate one cube and after completing 90degree I am trying to display it. And that is also not working, but here goes my code:-
var yflower:Texture2D;
var bflower:Texture2D;
var flowerRect:Rect = Rect(100, 100, 100, 100);
var pivotPoint:Vector2=Vector2(100, 100);
var rotAngle=0;
//var firstCycle:boolean=false;
//var pivotPoint2:Vector2=Vector2(220,220);
var flowerRect2:Rect = Rect(0, 300, 300, 100);
function OnGUI ()
{
// GUI.DrawTexture(flowerRect, yflower, ScaleMode.ScaleToFit,true, 0);
if (rotAngle<90)
{
GUIUtility.RotateAroundPivot(rotAngle, pivotPoint);
GUI.DrawTexture(flowerRect, yflower, ScaleMode.ScaleToFit,true, 0);
rotAngle++;
}
else if(rotAngle>=90)
{
GUI.DrawTexture(flowerRect2, yflower, ScaleMode.ScaleToFit,true, 0);
Debug.Log("bflower");
}
}
Its rotating once and disappears. :-(!!
image links are not working, I think! So here are the links:- Figure One:- http://postimage.org/image/c6egw05bz/ Figure Two:- http://postimage.org/image/yttq25kvz/
Could you make the images flat planes in front of the camera, and then rotate them using transform.rotation? In my experience, trying to rotate elements in the GUI system in a consistent and sane way is surprisingly difficult.
Currently the game is not completely designed and I am in constant communication with my artist (should go for 2D/3D). So I thought I'll try out 2D first, then I came up with this GUITexture and stuffs. According to my plan these cubes will be inscets and plants and stuffs like that and 2D/3D does depends on the budget. I do prefer 3D. So'll roll back to you after trying. thnx for the tip!
Answer by IJM · Jan 24, 2012 at 01:56 PM
You can use this to check for click:
var rect = Rect (0, 0, 150, 150); // Rect around your circle
if (rect.Contains(Input.mousePosition))
if(Input.GetMouseButtonDown(0))
//Do something on left click
To rotate your texure, you can do this:
var matrixBackup = GUI.matrix; // U need to save your original matrix
GUIUtility.RotateAroundPivot(angle, pivot); // In your case, angle will lerp from 0 to 90
GUI.DrawTexture(rect, texture);
GUI.matrix = matrixBackup; // And restore it at the end
hmmm... Ivan, Can you please tell me what this matrix is for? And when I tried with your code I got some other place as pivot point. var pivot:Vector2=Vector2(150, 150); but that was not my pivot point. Thanx for the hands!
No it is not. You have to use same rect for your texture, "rect.Contains" call, and your pivot. To calculate the center of a rect you can do this: var pivot:Vector2=Vector2(rect.x + rect.width/2, rect.y + rect.height/2); In 3D computer graphics, 4x4 transformation matrices are used to position/rotate/scale objects. Np. mate, any time :D
But mate here I'm trying to rotate 90deg first and then pause until there is a response from the user. And again my first pivot point will be bottom right for the first press and then for the second press the bottom left will be the pivot point. Then for the third press it will be top left. And $$anonymous$$I didn't understand the usage of matrix here.
Ok. I think it'd definitely be easier just to use planes with textures on them. The matrix is what transforms between the x-y coordinates of the gui system (where you put textures and other elements) and the x-y coordinates of the screen. You can use it to rotate and scale gui elements, but as I've said it's difficult to animate them in the way that you seem to need.
rotating a cube is easier than rotating a GUITexture2D. Thanx syclamoth.
Your answer
Follow this Question
Related Questions
fbx animation beats script animation? 2 Answers
Rotate around a pivot between two points? 2 Answers
How to make a script access animations from a child prefab 1 Answer
wrong rotation in animation per script 0 Answers
when Rotateing direction prob 1 Answer