[SOLVED]Possible Alternation of Transform.Rotate

I closed the other question due to lack of info.

The following is the case.

I have built a dashboard in unity, made movable pointers and made up algorithms for their degree rotations.

But i stumbled upon a huge problem.

I am reading my values (speed, rpm, engine temperature u get the deal) out of a TextAsset, and i need to make the pointer turn the other way when the car goes slower (DUH)…

Is there a Solution you could think of? If yes, pleaaaase let me know :slight_smile:

EDIT : Turning into the other direction was solved by simply inserting a negative value (DERP). The only thing missing now is Stopping the pointer after he rotated the certain amount, saving the old value for checking and the algorithm for the car going slower :confused:

MOAR EDIT : Looked through the Scripting Reference, nothing there concerning the hold of a rotation in the way i need it… gonna be a real hassle to code this i guess

EVEN MOAR EDIT : Here’s the Script

function lese_datei() // Öffnen und Parsen der Datei.

	{
		Zeilen = CSVDatei.text.Split("

"[0]); // Parsen an Zeilenendekennung

		for(i=4;i < Zeilen.length; i++)
	
			{
	
				
				Werte = Zeilen*.Split(";"[0]);       // Parsen am Semikolon*
  •  		var Geschwindigkeit_pos  = int.Parse(Werte[4]);*
    
  •  		var Umdrehungen_pos = int.Parse(Werte[8]);*
    
  •  		var Motorhitze_pos = int.Parse(Werte[9]);*
    

Geschwindigkeit_rotation = (Geschwindigkeit_pos / 300.0) * 180.0;
Umdrehungen_rotation = (Umdrehungen_pos / 8000.0) * 240.0;

  •  		Motorhitze_rotation = Motorhitze_pos;*
    

*print(“Zeilennummer:” + i + "
Geschwindigkeit:“+Geschwindigkeit_pos+”
“+“RPM:”+Umdrehungen_pos+”
“+“Temperatur:”+Motorhitze_pos+”

“+“Gradzahl speed:”+Geschwindigkeit_rotation+”
“+“Gradzahl rpm:”+Umdrehungen_rotation+”
"+“Gradzahl Temperatur:”+ Motorhitze_rotation);*

  •  		yield WaitForSeconds(0.1); // lesetakt!*
    
  •  	}*
    

Geschwindigkeit.transform.Rotate(0,Geschwindigkeit_rotation*Time.deltaTime,0); // HERE I WANT TO STOP AFTER REACHING THE VARIABLES VALUE

  • }*

function Start() //wird NICHT einmal pro Frame aufgerufen, deswegen funktion hier rein!
{

  • lese_datei();*
    }
    Nobody can answer this? D:
    SUM MOAR EDIT HURR :
    I found out something extremely weird. If i add my calculated degree position to the X rotation of my pointer in the editor view, i get the right position. BUT! if i set it as X rotation in my script, it totally messes Up. I NEED to rotate it as Y rotation in my script to properly rotate it, but if i use it as Y rotation in the editor view it totally screws up.
    Help?
    :slight_smile:
    EDIT : Leaving this question till i leave the office, going to delete it then. i don’t see a point in leaving this one up
    Edit : SOLVED SOLVED AND EVEN MORE SOLVED!!!
    Here’s the Guide to it, in case someone else got the same Problem!!!
    I’ve Created an Empty Game Object, and placed it right to a Pointer. Then, i made it the pointer’s Parent.
    Because empty GameObjects come completely without rotation, they are way more accurate than the already rotated pointers.
    Meaning, if i make the empty GameObject the target of my rotation inside my script, The values will be way easier to interpolate, and also more accurate!!!
    Thanks to graham Dunnett supporting me via skype.
    I hope somebody can make use of this info as well

Rotations can be quite a pain… I’m not quite sure what your asking here but if your asking about how to set a limit on your rotation have you considered mathf.clamp?

http://unity3d.com/support/documentation/ScriptReference/Mathf.Clamp.html

Edit

Please don’t bump questions man, people will help if they can. I’m afraid I don’t speak German so I’m going to have to bow out of helping you at this stage.

My suspciain is that as you’ve * by Time.deltaTime you are calling this every frame. Using Mathf.Lerp is probably what your after.

Edit 2

Right try this:

Geschwindigkeit.transform.Rotate(0,Mathf.Lerp(Geschwindigkeit.transform.eulerAngles.y, Geschwindigkeit_rotation, Time.time),0);

Where it says Time.time is the time you want the rotation to occur in… see http://unity3d.com/support/documentation/ScriptReference/Mathf.Lerp.html for more