- Home /
Stopping all movement along axis?
Is there a way to stop all movement when a button is pressed.
So what I would like to do is when I play an animation, with the Input of a button, the character stops moving along any axis.
function Update () {
if(Input.GetMouseButton(0))
animation.Play("my_animation");
}
If there is a way, what should I add in to stop all movement on the input of a key?
Thanks for any incite into this!
Answer by japanitrat · Sep 11, 2011 at 04:42 PM
animation.Stop();
stops all currently active animations, but also rewinds it. If you want to pause an animation, you will need to set its speed down to zero.
for (var state : AnimationState in animation) {
state.speed = 0;
}
Be careful though, the animation is still "playing", so if you want to play it again, you just need to set the speed to 1 (normal) again.
I should have been more clear on my question, I was more looking for a script that stops movement along the x,y and z axis on input of a button.
So if I'm using a third person controller, If I hold down the button then the speed that I'm moving at is set to 0, so I am not moving anywhere.
if you have control over the script that makes the movement (preferred), you first look for the "pause" key and if it has been pressed, you do not process any other keys in that behaviour.
if not, just set the x/y/z components to a fixed value as long as the button is pressed (namely to the values that were present when the user started to press the key).
Your answer
Follow this Question
Related Questions
Help with mouse and keyboard movement. 0 Answers
Script on moving object doesn't work? 1 Answer
How would I script a simple path animation in C# 1 Answer
Animation / Distance 0 Answers