Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Bono · Oct 04, 2010 at 02:02 PM · locomotionidlestops

Locomotion Problem with JumpAndIdle waitanimation stops for a few seconds!

Hi ! This is a script in the Locomotionsystem, If you have notice that the idle stop and starts again, this has something to do with the JumpAndIdle script. If I remove that script the wait Idle works. But with the JumpAndIdle script it stops and start again. Does anybody know what to do with this script JumpAndIdle? The waitidle stops for 3-5 scound and starts again! Does anybody know what to do so it dont stop.

If you have the LocomotionSystem example you can see it for your self! Or you can download it here!

http://unity3d.com/support/old-resou...ty-extensions/

Thankyou in advance!!!! Here is the script in C#!

enter code here

using UnityEngine; using System.Collections;

[RequireComponent(typeof(AlignmentTracker))] public class JumpAndIdle : MonoBehaviour {

public AnimationClip jumpingAnimation; public float jumpTimeStart = 0.0f; public float fallTimeThreshold = 0.2f; public AnimationClip waitingAnimation;

private bool doJumping = false; private bool doWaiting = false;

//private LegAnimator legA; private AlignmentTracker align; private CharacterMotor cm;

private bool grounded; private bool waiting = false; private float idleTimer = 0.0f; private float fallingTimer = 0.0f;

// Use this for initialization void Start () { //legA = GetComponent(typeof(LegAnimator)) as LegAnimator; align = GetComponent(typeof(AlignmentTracker)) as AlignmentTracker; cm = GetComponent(typeof(CharacterMotor)) as CharacterMotor; grounded = false;

 // Only use jumping if the jumping animation has ben set
 if (jumpingAnimation!=null) {
     animation[jumpingAnimation.name].wrapMode = WrapMode.ClampForever;
     doJumping = true;
 }

 // Only use idle animation if it has been set
 if (waitingAnimation!=null) {
     animation[waitingAnimation.name].wrapMode = WrapMode.ClampForever;
     doWaiting = true;
 }

 // Start with locomotion
 animation.Play("locomotion");

}

void OnEnable () { if (animation["locomotion"]!=null) animation["locomotion"].weight = 1; }

// Update is called once per frame void Update () { float speed = align.velocity.magnitude;

 // CrossFade quick to jumping animation while not grounded
 if (doJumping) {
     // If the jump button has been pressed
     if (cm.jumping) {
         grounded = false;
         waiting = false;
         // Fade to jumping animation quickly
         animation.CrossFade(jumpingAnimation.name, 0.1f);
         animation[jumpingAnimation.name].time = jumpTimeStart;
         animation[jumpingAnimation.name].wrapMode = WrapMode.ClampForever;
     }
     // If the character has walked over a ledge and is now in air
     else if (grounded && !cm.grounded) {
         grounded = false;
         waiting = false;
     }
     // If the character has landed on the ground again
     else if (!grounded && cm.grounded) {
         grounded = true;
         waiting = false;
         fallingTimer = 0;
         // Fade to locomotion motion group quickly
         animation.CrossFade("locomotion", 0.1f);
     }
     // If the character is falling
     else if (!grounded && fallingTimer<fallTimeThreshold) {
         fallingTimer += Time.deltaTime;
         if (fallingTimer>=fallTimeThreshold) {
             // Fade to jumping motion group slowly
             animation.CrossFade(jumpingAnimation.name, 0.2f);
             animation[jumpingAnimation.name].time = jumpTimeStart;
             animation[jumpingAnimation.name].wrapMode = WrapMode.ClampForever;
         }
     }
 }

 // CrossFade to waiting animation when inactive for a little while
 if (doWaiting) {
     if (speed==0) {
         idleTimer += Time.deltaTime;
         if (idleTimer>3) {
             // if the idle animation is not in the middle of playing
             if (
                 animation[waitingAnimation.name].time==0
                 || animation[waitingAnimation.name].time>=animation[waitingAnimation.name].length
             ) {
                 // Then rewind and play it
                 animation[waitingAnimation.name].time = 0;
                 animation.CrossFade(waitingAnimation.name);
                 animation[waitingAnimation.name].wrapMode = WrapMode.ClampForever;
                 waiting = true;
             }
             // Don't play again for a little random while
             idleTimer = -(2+4*Random.value);
         }
     }
     // If we have started to move again
     else if (speed>0 && waiting) {
         // Crossfade to locomotion
         animation.CrossFade("locomotion");
         waiting = false;
         idleTimer = 0;
     }
 }

}

}

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 Bono · Oct 04, 2010 at 05:38 PM

I think it works now, I took away line 109. idleTimer = -(2+4*Random.value); and change it to idleTimer += Time.deltaTime; But I dont know if this is the right way to do it? But it looks like its working, but I have to test more! If someone know a better way you are welcome! Bono

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to say OR in C#. 1 Answer

Anyone have a 'click to move here' character controller script? 1 Answer

unity game stops when animation starts problem. 1 Answer

Slow down and play walk animation on left shift? 3 Answers

How can I make Locomotion to work over network? 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