• 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
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

People who like this

0 Show 0
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

  • Sort: 
avatar image

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

People who like this

0 Show 0 · 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

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

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

Simple jump code? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges