gdv
1
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?
MrSoad
2
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;
}
}