Need help with this Rotation Script (fixes)

Hello,

I’m making my dashboard and successfully completed the alorithms to rotate my needles.

I wish to rotate them a variable amount of degrees WITHIN 1.5 Seconds.

Is it possible to use the Time class for this?

i don’t want my needles jump from position to position, i want them to rotate!

can somebody help me? i didnt find anything useful in the scripting reference

EDIT : Script incoming, take cover :open_mouth:

var Source : TextAsset;

var ZeigerSpeed : GameObject;
var ZeigerRPM   : GameObject;
var ZeigerHitze : GameObject;


var DrehungSpeed = 0.0;
var DrehungRpm = 0.0;
var DrehungHitze = 0.0;

var DrehungSpeed_alt = 0.0;
var DrehungRpm_alt = 0.0;
var DrehungHitze_alt = 0.0;










function Dashboard()
{
	var lines = Source.text.Split("

"[0]);

	for(var i = 4; i < lines.Length; i++)
	{
		var values = lines*.Split(";"[0]);*
  •  DrehungSpeed = int.Parse(values[4]);*
    
  •  DrehungRpm = int.Parse(values[8]);*
    

_ DrehungSpeed = (DrehungSpeed/300.0)*180.0;_

  •  DrehungRpm = (DrehungRpm/8000.0)/240.0;		*
    
  •  ZeigerSpeed.transform.Rotate(0,0,DrehungSpeed);*
    
  •  ZeigerRPM.transform.Rotate(0,0,DrehungRpm);*
    
  •  DrehungSpeed_alt = DrehungSpeed;*
    
  •  DrehungRpm_alt = DrehungRpm;*
    
  •  if(i>4)*
    
  •  {*
    
  •  	DrehungSpeed = DrehungSpeed - DrehungSpeed_alt;*
    
  •  	DrehungRpm = DrehungRpm - DrehungRpm_alt;*
    
  •  }*
    
  •  if(DrehungSpeed < DrehungSpeed_alt)*
    
  •  {*
    
  •  	DrehungSpeed = -(DrehungSpeed_alt - DrehungSpeed);*
    
  •  }*
    
  •  if(DrehungRpm < DrehungRpm_alt)*
    
  •  {*
    
  •  	DrehungRpm = -(DrehungRpm_alt - DrehungRpm);*
    
  •  }*
    
  •  if(DrehungSpeed == DrehungSpeed_alt)*
    
  •  {*
    
  •  	DrehungSpeed = 0;*
    
  •  }*
    
  •  if(DrehungRpm == DrehungRpm_alt)*
    
  •  {*
    
  •  	DrehungRpm = 0;*
    
  •  }*
    
  • }*
    }

function Start()
{

  • Dashboard();*
    }

*function Update(){} *
EDIT: Rotation works now, inverting the values properly does not :confused: i’m totally out of ideas

This is just a maths question. At time now your needle is at angle theta1. In time now+1.5 you need your needle to be at angle theta2. So you need to rotate by (theta2-theta1)/1.5 degrees per second. Call this deltaThetaPerSecond.

The Time Class has a member called deltaTime (http://unity3d.com/support/documentation/ScriptReference/Time-deltaTime.html). This is documented as telling you how much time the last frame took to display. So, multiply deltaThetaPerSecond by Time.deltaTime and this tells you how many degrees you need to rotate your needle by in the current frame.

After 1.5 seconds you no longer need to make this change, so, in your Update() function after you have counted 1.5 second have passed just set deltaThetaPerSecond to zero. Now your needle won’t rotate any more.

If you happen to get a new speed value inside the 1.5 second period, just re-compute deltaThetaPerSecond from the current angle and the new desired angle.

var currentAngle = 0.0; // this is the rotation of the needle in degrees
function lese_datei()
{
  for (;;) // do your current looping stuff
  {
    //csv reading stuff and compute desiredAngle
    deltaThetaPerSecond = (desiredAngle - currentAngle) / 1.5;
    yield WaitForSeconds(1.5);
  }
}
function Update()
{
  var deltaAngle = deltaThetaPerSecond * Time.deltaTime;
  currentAngle += deltaAngle;
  Umdrehungen.transform.Rotate(0,0,currentAngle);
}