- Home /
How would I go about making an animation affected by this script?
So I made an animation called "M1911Idle" and it is attached to the the arm holding it. It works, but when I use another script to "add weight" to the gun, like when you turn, the gun moves a bit, not just sit in one place. But, with the "M1911Idle" animation running, it doesn't work. How could I go about making this script work while the animation is playing?
Script: public var MoveAmount : float = 1;
public var MoveSpeed : float = 2;
public var GUN: GameObject;
public var MoveOnX : float;
public var MoveOnY : float;
public var DefaultPos : Vector3;
public var NewGunPos : Vector3;
function Start(){
DefaultPos = transform.localPosition;
}
function Update () {
MoveOnX = Input.GetAxis( "Mouse X" ) *Time.deltaTime * MoveAmount;
MoveOnY = Input.GetAxis( "Mouse Y" ) *Time.deltaTime * MoveAmount;
NewGunPos = new Vector3 ( DefaultPos.x+ MoveOnX, DefaultPos.y+ MoveOnY, DefaultPos.z);
GUN.transform.localPosition = Vector3.Lerp(GUN.transform.localPosition, NewGunPos , MoveSpeed * Time.deltaTime);
}
Thanks.
Also, the script above is attached to the arm holding the gun.
Answer by LukaKotar · Dec 07, 2013 at 09:53 PM
Simple: create an empty game object, and put your animated object as a child to it. Now just attach your script to the newly created parent object.
Didn't seem to work, here's how it's set up currently:
The script above is attached to "Holder" (the empty game object you said to create) and it holds the arm and the gun. The "$$anonymous$$1911Arm" has the "$$anonymous$$1911Idle" animation.
Your answer
Follow this Question
Related Questions
Animation & Script Help 2 Answers
Stop animation and back to default location 3 Answers
script for animation play 1 Answer
FPS game walk animation script help 1 Answer
gun bob and jerk animation 2 Answers