• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by thedumbone74 · Jun 09, 2012 at 08:43 PM · jumpplayanimate

jump animation doesn't play all the way if i am moving

how can i just tap the jump key (space bar) and have my "jump animation" play all the way through while i am moving ?

this is my animation script,

function Start () {

}

function Update () {

 if (Input.GetAxis("Vertical") > 0)
       animation.Play ("jess walk");
       
 if (Input.GetAxis("Horizontal") < 0)
    animation.Play ("jess left");
   
 if (Input.GetAxis("Horizontal") > 0)
    animation.Play ("jess right");

 if (Input.GetButton("Jump"))
     animation.Play ("jess jump");



}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by static_cast · Nov 11, 2013 at 01:03 AM

Hey, I think there this is your problem:

I think that because animations while you are pressing keys, which also have their own walking animations, they are overlapping the jump animation or stopping it all-together.

To fix this, you could...

  1. allow the player to only move when they are grounded [this will disallow movement while jumping, of course],

  2. or have a jump variable control whether or not they are jumping...


Here is code that you could use to get input movement, which I modified from my games [Which uses the first method, checking whether or not they are grounded, to determine whether or not they should move]:

 #pragma strict
 var movementSpeed = 1.0;
 var jump : KeyCode;
 
 private var x = 0.0;
 private var z = 0.0;
 private var grounded = true;
 
 function Start()
  {
  rigidbody.freezeRotation = true;
  }
 
 function Update()
  {
  if(grounded)
   {
   x = Input.GetAxis("Horizontal") * movementSpeed * Time.deltaTime;
   z = Input.GetAxis("Vertical")   * movementSpeed * Time.deltaTime;

   //Added this script
   if(Input.GetAxis("Vertical") > 0)
   animation.Play("jess walk");
    
   if(Input.GetAxis("Horizontal") < 0)
   animation.Play("jess left");
    
   if(Input.GetAxis("Horizontal") > 0)
   animation.Play("jess right");
   //----
 
  }
  grounded = Physics.Raycast(transform.position, Vector3.down, 0.1);
 
  transform.Translate(x, 0, z);
 
  if(Input.GetKeyDown(KeyCode.Space) && grounded)
   {
   rigidbody.velocity = Vector3(0, Mathf.Sqrt(20), 0);

   //And also this one
   if(Input.GetButton("Jump"))
    animation.Play("jess jump");
   //----

   }
  }

Note: you will need your character to be a rigidbody [And have a collider] in order for this script to work.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

what is the jump axis for if (Input.GetAxis(" ? ") 2 Answers

Unknown Identifier maxSlope 1 Answer

Simple jump code? 1 Answer

Animation + Scripting = I Don't Understand (Help) 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges