Hello, I create a sway script for my flashlight and attached it to the gameobject(flashlight).
Now the problem is that when I enable the animator in the gameobject(flashlight) the sway doesnt work,but when I disable it,it does work. This is the script :
#pragma strict
var flashLight : Transform;
var xSwayAmount : float = 0.1;
var ySwayAmount : float = 0.05;
var maxXAmount : float = 0.35;
var maxYAmount : float = 0.2;
private var vector3 : Vector3;
var smooth : float = 3.0;
function Start () {
vector3 = flashLight.localPosition;
}
function Update () {
var fx : float = -Input.GetAxis("Mouse X") * xSwayAmount;
var fy : float = -Input.GetAxis("Mouse Y") * ySwayAmount;
if(fx > maxXAmount)
fx = maxXAmount;
if(fx< -maxXAmount)
fx = maxXAmount;
if(fy > maxYAmount)
fy = maxYAmount;
if(fy < -maxYAmount)
fy = -maxYAmount;
var detection : Vector3 = new Vector3(vector3.x + fx, vector3.y + fy, vector3.z);
flashLight.localPosition = Vector3.Lerp(flashLight.localPosition, detection, Time.deltaTime * smooth);
}
Has anyone got any idea why is this happening ? I need the animator to play my animations so I can’t just disable it.Thank you.