Search Unity

Animation keypress problem

Discussion in 'Animation' started by derbosewicht, Dec 31, 2014.

  1. derbosewicht

    derbosewicht

    Joined:
    Dec 31, 2014
    Posts:
    1
    Hello all, joined the forum to just ask this question, although I'm sure ill have more!

    This is the code I am using to get gun sway while my character is running. My issue, is that its starts swaying before I press "w" and just continues and continues. The goal is to press "w" and then the animation start, and stop when "w" is not pressed.

    function Update()
    {
    if(Input.GetKeyDown("w"))
    {
    animation.Play("walkingbehavior", PlayMode.StopAll);
    }
    }
     
  2. wizardious

    wizardious

    Joined:
    Dec 31, 2009
    Posts:
    189
    If your making an FPS you might want to check out these assets. They contain examples of code similar to what your doing, and you can look at the code to see how they do it.
    http://u3d.as/content/dastardly-banana-productions-llc/fps-constructor/2yA
    http://www.fpscontrol.com/
    Edit: The fps constructor is old if you want to try it you have to change a line of code in the first one that comes up as error. I think it's AimMode.js
    Code (JavaScript):
    1.  
    2. // Instead of:
    3.  
    4.  
    5. 9.EditorGUIUtility.LookLikeInspector();
    6.  
    7.  
    8. 10.// Use:
    9.  
    10.  
    11. 11.EditorGUIUtility.labelWidth = 0;
    12.  
    13.  
    14. 12.EditorGUIUtility.fieldWidth = 0;
    15.  
    You'll also have to set up a lot of inputs!
     
    Last edited: Jan 3, 2015
unityunity