- Home /
Need help with rotation script.
HI,this is script what i wrote,but i wasn't expecting that its gonna work soo wrong. Well problem is : when i press "n" key the map rotates wrong, it rotates like "up" by 90 degrees,but what i want is,i want that map rotates around its axis (90 degrees). Around its axis basically. And also can anyone modify script correctly,that when i press again "n" button,map rotates back to its position ( - 90 degreess (back)),thanks for attention,i hope you understand me.
Here is the script:
 var map : Transform;
 var rotateSpeed : float;
 private var mapRotation : float;
 
 function Update()
 {
 if(Input.GetKeyDown("n"))
 {
 mapRotation -= 90;
 }
 map.rotation.x = Mathf.Lerp(map.rotation.x, mapRotation, rotateSpeed);
 }
This line is wrong,or all script?
 map.rotation.x = Mathf.Lerp(map.rotation.x, mapRotation, rotateSpeed);
Answer by joonturbo · Nov 16, 2013 at 04:33 PM
try doing it without (s)Lerping first, then it should look something like this:
 var map : Transform;
 var rotateSpeed : float;
 private var mapRotation : float;
  
 function Update()
 {
    if(Input.GetKeyDown("n"))
    {
      mapRotation -= 90;
    }
    map.rotation = Quaternion.Euler(map.eulerAngles.x, mapRotation, map.eulerAngles.z);
 }
Ten the easiest way to continue make this smoother instead of choppy, is to learn how to use iTween, a free tweening/smoothing library for Unity.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                