• 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 /
This question was closed May 19, 2013 at 09:52 PM by KMKxJOEY1 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by KMKxJOEY1 · May 07, 2013 at 09:29 PM · runrunninglocomotionsprintsprinting

What's wrong with my sprinting logic?

it seems like my 'down' boolean isn't updating, any help plz?

Here is my code:

     public void sprintManager()
     {
         if(needsSprint)
         {
             if(down)
             {
                 CurrentWeapon.WeaponTransform.animation[CurrentWeapon.sprintLoopAnim].speed = 0.5f;
                 CurrentWeapon.WeaponTransform.animation.CrossFade(CurrentWeapon.sprintLoopAnim,0.2f);
             }
             else
                 down_to_sprint();
         }
         else
         {
             up_from_sprint();    
         }
     }
     
     void down_to_sprint()
     {
         CurrentWeapon.WeaponTransform.animation[CurrentWeapon.sprintInAnim].speed = 0.5f;
         CurrentWeapon.WeaponTransform.animation.CrossFade(CurrentWeapon.sprintInAnim,0.2f);
         if(animation_finished(CurrentWeapon.WeaponTransform.animation[CurrentWeapon.sprintInAnim].name))
             down = true;
     }
     
     void up_from_sprint()
     {
         if(down)
         {
             CurrentWeapon.WeaponTransform.animation[CurrentWeapon.sprintOutAnim].speed = 0.5f;
             CurrentWeapon.WeaponTransform.animation.CrossFade(CurrentWeapon.sprintOutAnim,0.2f);
             if(animation_finished(CurrentWeapon.WeaponTransform.animation[CurrentWeapon.sprintOutAnim].name))
             {
                 down = false;
                 force_idle();
             }
         }
     }
     
     public bool animation_finished(string anim)
     {
         if(CurrentWeapon.WeaponTransform.animation.IsPlaying(anim) || CurrentWeapon.WeaponTransform.animation[anim].normalizedTime >= 1 )
             return true;
         else
             return false;
     }
Comment
Add comment · Show 3
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 ThunderEyed · May 07, 2013 at 09:40 PM 0
Share

Could you post something about how needSprint is toggled and how these booleans are initialized? NeedSprint =true if something is pressed? Down is default true or false?

avatar image KMKxJOEY1 · May 07, 2013 at 10:37 PM 0
Share

down is default false and needSprint is toggled by the player speed, but here is the code if you would like to take a look:

     //walking
             if(walkingstate == WalkingState.Running)
             {
                 needsSprint = true;
                 if(down)
                     down = false;
             }
             else if(walkingstate == WalkingState.Walking)
             {
                 WalkAnimationHolder.animation["walking"].speed = Velocity$$anonymous$$agnitude / walkSpeed;
                 WalkAnimationHolder.animation.CrossFade("walking", 0.2f);
                 WalkAnimationHolder.transform.rotation = WalkAnimationHolder.transform.parent.rotation;
                 
                 needsSprint = false;
             }
             else
             {
                 needsSprint = false;
 
                 if(!isAiming)
                 {
                     WalkAnimationHolder.animation.CrossFade("spreader_idle", 0.2f);
                     WalkAnimationHolder.transform.rotation = WalkAnimationHolder.transform.parent.rotation;
                 }
                 else
                 {
                     WalkAnimationHolder.animation.Rewind();
                     ADSHolder.localPosition = Vector3.Lerp(ADSHolder.localPosition, CurrentWeapon.Scopes[CurrentWeapon.CurrentScope].ADSPos, 1f);    
                 }
             }
avatar image KMKxJOEY1 · May 13, 2013 at 09:39 PM 0
Share

bumpp, :)

1 Reply

  • Sort: 
avatar image
0

Answer by KMKxJOEY1 · May 19, 2013 at 09:52 PM

fixed on my own

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

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

13 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

Related Questions

How to disable sprinting when slider reaches zero. 1 Answer

Mid air "sprint" 2 Answers

Animations Can't Be Execute 0 Answers

How do I add a sprint recharge 1 Answer

unity 2d platformer dash attack. 1 Answer

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