- Home /
animation problem (transform.position)
I have a third person witch can boxing and throw fire balls. Every time he do hes animation it returns to the pisition where I created the animations. How can I do the animations without the character will change hes position?
here is a part of the scrip of my character:
function Update () { var controller : CharacterController = GetComponent(CharacterController); transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
//Shooting!
if(Input.GetButtonDown("Jump"))
{
animation.Play("BodyThrow");
var bullit = Instantiate(bullitPrefab, transform.Find("SpawnPointB1").transform.position, Quaternion.identity);
bullit.tag = "bobProjectile";
bullit.rigidbody.AddForce(transform.forward * 5000);
}
if(Input.GetKeyDown("v"))
{
animation.Play("BobBoxing");
}
}
And i need little help to delay the bullet, that he wait a second after the animation is starts, shoot, and wiat a few seconds again.
Answer by Uriel_96 · Feb 12, 2011 at 06:44 PM
to do what you want I recommend you to do your animation without moving the position of the object and then change the position of the object by code with translate and then for the delay there is something called yield WaitForSeconds that waits for the seconds you put in the parenthesis.
OK, for the yield WaitForSeconds make sure you dont put it in the Update, what I actually do sometimes to get it work is something like this:
function Update(){
DoSomething();
}
function DoSomething(){
yield WaitForSeconds(2);
//Do something
}
Its still doesn't work... The animation and the delay...
for delay it may work, maybe you put it in the wrong place and for the other, you may need to see more about animation and like that get your problem because it depends on many things, like if is default or pingpong, or cross-fade so I recommend you to see more abot animation: http://unity3d.com/support/documentation/$$anonymous$$anual/Animation.html, http://unity3d.com/support/documentation/$$anonymous$$anual/Animation%20Scripting.html
I tried everything! I just want it to do the animation only ones if I click on key and that all, it do it only ones,everything good but it return to the start point! I didn't write it on the code and you can see it not there!
About the delay, i put that code in my script but I get this error: "Script error: Update() can not be a coroutine.". What it meen?
for the animation I don't got it, some day I had that problem to, but I don't remember how I solve it, and for the delay, I forgot to say you that you can't use it in Update function, what I usually do is something that Im going to modify in the answer.
Ty for Tring to help anyway. I sucsseed to add the delay finely but not the animation
Your answer
![](https://koobas.hobune.stream/wayback/20220613103928im_/https://answers.unity.com/themes/thub/images/avi.jpg)