- Home /
Animator canceling a script (sway)
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.
Answer by yagizpoyraz · Jul 17, 2014 at 07:49 AM
Create an empty gameobject (will be called parent) which holds your current gameobject. Move your animator to your parent object, sway can stay on your gameobject.
This should work.
THANK YOU!!!!!!!!!!!!!!! AND WHY DOES IT HAS -1 VOTES WTF IT WORKED THANKS $$anonymous$$AN!
Answer by smallbit · Jul 17, 2014 at 02:44 AM
(just a guess) It might be because your animation overrides the sway?. You said you have sway script and animator in the same GameObject, try to create another GameObject, attach sway script to it, and make your current GameObject(flashlight) with animator as a child of that GameObject (reset Transform).Let me know how it works for you.
Your answer
Follow this Question
Related Questions
How to get a smoother slow motion 0 Answers
Projectile movement in 3D 1 Answer
Inspector Problems or possible miss script. 0 Answers
Load Large Size Model Unity3d 2 Answers
How to make a mesh adjust its form around specific points 1 Answer