- Home /
 
 
               Question by 
               gdv · Dec 10, 2014 at 02:47 PM · 
                movementsmoothflashlighty  
              
 
              Smooth Flashlight Movement
Hey! I want to make a smooth flashlight movement but the spotlight only moves smoothly to the x of the camera, and not to the y too.
Here's the script:
 var target : GameObject;
 var speed : float;
 
 function Update() {
     transform.rotation = Quaternion.Slerp (transform.rotation, target.transform.rotation, Time.smoothDeltaTime * speed);
 }
 
               What's the problem?
               Comment
              
 
               
              Answer by MrSoad · Dec 10, 2014 at 02:46 PM
Try this, I'm assuming you want it to work in relation to the Main Camera :
 #pragma strict
 
 //Transform vars.
 private var tMy_Transform : Transform;
 private var tMain_Camera_Transform : Transform;
 
 //Rotate speed var.
 private var fMy_Rotate_Speed : float;
 
 function Awake () {
 
     //Connect to Objects and Scripts.
     tMain_Camera_Transform = GameObject.Find("Main Camera").transform;
 }
 
 function Start() {
 
     //Get Transforms.
     tMy_Transform = transform;
     //Set Rotation Speed.
     fMy_Rotate_Speed = 8f;
 }
 
 function Update() {
 
     if (tMain_Camera_Transform != null) {
         //Rotate. 
         tMy_Transform.rotation = Quaternion.Slerp(tMy_Transform.rotation, tMain_Camera_Transform.rotation, Time.deltaTime * fMy_Rotate_Speed);
     } else {
         //Try and find Main Camera again.
         tMain_Camera_Transform = GameObject.Find("Main Camera").transform;
     }
 }
 
              No difference, the spotlight still rotates only to the x axis, I want it to rotate to both axis, x and y. Thanks anyway!
Odd, this works 100% on the Flashlight in my scene(I just tested it again to be absolutely sure). The problem is somewhere else, not the script, so :
Have you got a rigidbody on your flashlight? If you have then have you restricted the y rotation axis in the rigidbody settings?
Is your flashlight setup(aligned) along the correct axis?
Your answer