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 /
avatar image
0
Question by Abdul_Bari · Nov 09, 2019 at 07:39 PM · animationunity 5animatorjumpinganimation script

How to run my jump animation in unity3d?

Hello everyone, I have an issue with my jumping animation which I don't know how to run it and makes it work, I know it might be a stupid question, but I'm very beginner with unity and coding in general. I watched some tutorials about running and walking, which I made my character in blender 2.8 and I imported it to unity and everything works just fine. My problem is that I'm stuck with the jumping bit, and I don't know how it should look like in the animator as well as the script. Could anyone help me, please?. I have three animations for jumping, which is: jumping, falling and landing. I put the animation in the animator and I don't know if it is right or not. Here are some pictures to make it clearer. alt text The blend tree contain idle, walk and run animations and here is the code for movement:

public class Player : MonoBehaviour {

 [SerializeField] private float WalkSpeed;
 [SerializeField] private float RunSpeed;

 private float currentSpeed = 0f;
 private float speedSmoothVelocity = 0f;
 private float speedSmoothTime = 0.1f;
 private float rotationSpeed = 0.3f;
 private float gravity = 9.8f;
 private float JumpSpeed = 50f;
 private Vector3 moveDirection = Vector3.zero;
 
 private Transform MaincameraTransform = null;

 private CharacterController controller = null;
 private Animator animator = null;

 private void Start()
 {
     controller = GetComponent<CharacterController>();
     animator = GetComponent<Animator>();
     MaincameraTransform = Camera.main.transform;
 }

 private void Update()
 {
     Movement();
     Jump();
     
 }

 private void Movement()
 {
     Vector2 movementInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
     Vector3 forward = MaincameraTransform.forward;
     Vector3 right = MaincameraTransform.right;

     forward.y = 0;
     right.y = 0;

     forward.Normalize();
     right.Normalize();

     Vector3 DesiredMoveDirection = (forward * movementInput.y + right * movementInput.x).normalized;

     Vector3 gravityVector = Vector3.zero;

     if (!controller.isGrounded)
     {

         gravityVector.y -= gravity;
     }

     if (DesiredMoveDirection != Vector3.zero)
     {
         transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(DesiredMoveDirection), rotationSpeed);

     }

     float targetspeed = WalkSpeed * movementInput.magnitude;

     if (Input.GetKey(KeyCode.LeftShift))
     {

         targetspeed = RunSpeed * movementInput.magnitude;
     }

     currentSpeed = Mathf.SmoothDamp(currentSpeed, targetspeed, ref speedSmoothVelocity, speedSmoothTime);

     controller.Move(DesiredMoveDirection * currentSpeed * Time.deltaTime);
     controller.Move(gravityVector * Time.deltaTime);

     animator.SetFloat("MovementSpeed", 0.5f * movementInput.magnitude, speedSmoothTime, Time.deltaTime);

     if (Input.GetKey(KeyCode.LeftShift))
     {
         animator.SetFloat("MovementSpeed", 1f * movementInput.magnitude, speedSmoothTime, Time.deltaTime);

     }


 }


screenshot-2019-11-09-at-180439.png (45.0 kB)
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 thakkarvishal96 · Nov 11, 2019 at 09:06 AM

@Abdul_Bari Kindly check where you put end of the animation? Its continuing walking or what?

Comment
Add comment · Show 1 · 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
avatar image Abdul_Bari · Nov 11, 2019 at 05:53 PM 0
Share

Hello, no because it keeps running the 3 jumping animations and I removed it because I think its wrong, do you have any solution, please?

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

212 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

Related Questions

How would I switch between 2 animation states connected to 1 state under input? 0 Answers

Check Animator State Animation Completed 0 Answers

root motion on in place animation 0 Answers

Button animator not playing. 0 Answers

How play an animation through collision (2D Game)? 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