- Home /
gui rotational issues
i am try to rotate a gui around a certain position but i am having trouble with the code.......here is what keeps happening. picture of problem here
i want that that circled gui in the case.....but when ever im moving around ( do a dive or something) it always finds some way of getting out of the gui (ignore the background grey gui and the compass one)
this is the script im using to do the horizon thing:
//Horizon Instrument
var X:float=1366;
var Y:float=768;
var mainskin : GUISkin; //This is to connect the script with the guiskin
var bgImage : Texture2D; // background image that is 256 x 32
var ypos : float= -24;
var xpos : float= -25;
var fgImage : Texture2D; // foreground image that is 256 x 32
var pitch = 0; // a float between 0.0 and 1.0
var tilt:float=0.0;
function OnGUI () {
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3(1.0*Screen.width/X, 1.0*Screen.height/Y, 1.0));
GUI.skin = mainskin; //The guiskin in use
//Frontneigung || Pitch forward backward
//210 ist der Zentrierpunkt in der Textur, der Horizont auf Null || 210 is the centerpoint in the texture, the horizon at 0
if (moveairplane.rotationx < 180) pitch = -210-moveairplane.rotationx;
else pitch = -210-moveairplane.rotationx+360;
// Seitenneigung || Tilt sidewards
tilt=moveairplane.rotationz;
// Create one Group to contain both images
// Adjust the first 2 coordinates to place it somewhere else on-screen
GUI.BeginGroup (Rect (Screen.width*5/8, Screen.height/10, Screen.width*0.8, Screen.height*0.8 ));
// Create a second Group which will be clipped
// We want to clip the image and not scale it, which is why we need the second Group
GUI.BeginGroup (Rect (0,0,82,90));
// Draw the foreground image
//---------------------------------------------------------
//Here comes the rotation
var matrixBackup:Matrix4x4 = GUI.matrix;
//var thisAngle:float = tilt;
var pos:Vector2 = Vector2(0,0); // rotatepoint in texture.
GUIUtility.RotateAroundPivot(tilt, pos);
var thisRect:Rect = Rect(0,pitch,84,512); //x position, y position, size x, size y
GUI.DrawTexture(thisRect, fgImage);
GUI.matrix = matrixBackup;
// End group
GUI.EndGroup ();
// Draw the background image. In front of the other texture. That`s why it is here.
GUI.DrawTexture (Rect (xpos,ypos,185,185), bgImage);
// End group
GUI.EndGroup ();
}
can anyone help me figure this out?
You should really be using GUIUtility.RotateAroundPivot- it's there to help, and it'll fix any problems you have with weird matricies.
Your answer
Follow this Question
Related Questions
GuiTexture For Jump A Character 0 Answers
The first object in selection grid can't be activated. Why? 1 Answer
Cant get my gui in the quiwindow to load there functions... 1 Answer
If statement only work once? 1 Answer
Temperature Script? 3 Answers