Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
  • Help Room /
avatar image
0
Question by KrissJonsi · Jan 27, 2018 at 06:29 AM · animationunity 5unity5jumpanimator controller

Can't jump after adding jump animation

For some reason I can't jump after adding a jump animation to my player.

my playerMove script includes the code that makes the animation play using: anim.Play ("JUMP00", -1, 1f);

Here is a picture of my animator controller: alt text

I've made sure that the animations work. The Wait00 animation works fine when playing, but after adding anim.Play ("JUMP00", -1, 1f); my player will no longer jump at all.

Here is my playerMove script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 [RequireComponent(typeof(Rigidbody))]
 [RequireComponent(typeof(CapsuleCollider))]
 public class PlayerMove2 : MonoBehaviour {
 
 #region UnityProporties
 
 [Header("Basic Movement")]
 public float moveForce = 50;
 public float airbornForceMultiplyer = 0.2f;
 public AnimationCurve speedGain;
 public float maxSpeed = 5;
 public float stillJumpMaxSpeed = 3;
 public float jumpForce = 6;
 [Tooltip("The minimum amount of time(ms) befor you can jump again.")]
 public float minimumJumpIterval = 100;
 [Tooltip("gravity + gravity * <this number>")]
 public float gravityMutiplyer = .5f;
 
 [Header("Physics")]
 public float groundCheckOffset = .01f;
 
 #endregion
 
 #region PrivateFields
 
 // Components
 private Rigidbody _rb;
 private SphereCollider _collider;
 public Animator anim;
 
 // Fields
 private bool _is_grounded = false;
 private int _last_jump;
 private bool _is_still_jump = false;
 
 #endregion
 
 // Use this for initialization
 void Start() {
     _rb = GetComponent<Rigidbody>();
     _collider = GetComponent<SphereCollider>();
     anim = GetComponent<Animator> ();
 }
 
 // Update is called once per frame
 void Update() {
 
     _is_grounded = GroundCheck();
 
     Movement();
 
     Jump();
 
     /**
      * ## Fast fall
      * if player is falling apply extra gravity.
      * physically correct gravity while falling
      * FEELS fake
     */
     if (_rb.velocity.y < 0) {
         _rb.AddRelativeForce(Physics.gravity * gravityMutiplyer);
     }
 
 }
 
 private bool GroundCheck() {
 
     if ((int)(Time.unscaledTime * 1000) < (_last_jump + minimumJumpIterval))
         return false;
 
     Ray ground_check = new Ray(
             transform.position + _collider.center,
             Vector3.down
         );
 
     RaycastHit hit;
     var rc_res = Physics.SphereCast(
             ground_check,
             _collider.radius,
             out hit,
             _collider.radius + groundCheckOffset
         );
 
     if (rc_res) {
         if (!hit.collider.CompareTag("Player")) {
             _is_still_jump = false;
             return true;
         }
     }
     return false;
 
 }
 
 /**
  * ## Get players inputs and handle the movement 
 */
 private void Movement () {
 
     Vector3 input_dir = GetPlayerInput();
 
     // limit the movement force by the maximum player speed
     // applied over a curve.
     float movent_mult = speedGain.Evaluate(
         _rb.velocity.magnitude / (_is_still_jump ? stillJumpMaxSpeed : maxSpeed)
     );
 
     var movement_force = new Vector3(
             input_dir.x * moveForce,
             0,
             input_dir.z * moveForce
         );
     movement_force *= movent_mult;
     if (!_is_grounded) movement_force *= airbornForceMultiplyer;
 
     // Apply the force to the Rigidbody
     _rb.AddRelativeForce(movement_force, ForceMode.Force);
 
 }
 
 /**
  * ## Jump condition
 */
 private void Jump () {
 
     if (Input.GetButton("Jump") && _is_grounded ) {
 
         anim.Play ("JUMP00", -1, 1f);
 
         if (_rb.velocity.sqrMagnitude< .1) {
             /*
              * if player jumps while standing still
              * max speed in the air is limited
             */
             _is_still_jump = true;
         }
 
         // prevents the downwards momentum from previos jumps
         // affecting this one
         _rb.velocity.Set(_rb.velocity.x, 0, _rb.velocity.z);
         _rb.AddRelativeForce(0, jumpForce, 0, ForceMode.Impulse);
         // prevents multiple jumps within the frames where the
         // margin of error for the ground check may say the player
         // is still grounded
         _last_jump = (int) (Time.unscaledTime* 1000);
         _is_grounded = false;
 
     }
 
 }
 
 private Vector3 GetPlayerInput () {
 
     var input_dir = new Vector3(
             Input.GetAxisRaw("Horizontal"),
             0,
             Input.GetAxisRaw("Vertical")
         );
     // The input vectors magnitude should never exceed 1
     return input_dir.normalized;
 
 }
 
 }

If you need any more information please ask and I will provide. Any help is appriciated.

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

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

311 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

I can't see or access a state in the Animation Controler 1 Answer

Character rolls forward,but slides back after animation 2 Answers

I am slowly falling down with the jump animation 4 Answers

Model does not play animation 0 Answers

I can't make transition from actual animation to previous one 1 Answer


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