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 Paceytron · Nov 03, 2016 at 04:54 AM · c#controllerrunningdebug-my-script

Why isn't speed changing?

Hey all, Pretty basic beginner at C# so I'm hoping it's a small thing that I've completely missed. I'm trying to do a 2D platformer with separate animations for walk and run. I've tried to set up a double tap feature to force the player to start running, except... it doesn't work.

What am I doing wrong?

     void FixedUpdate()
     {
         float h = Input.GetAxis("Horizontal");
  
         anim.SetFloat("Speed", Mathf.Abs(h));
  
         // Are we walking at full speed? If not, walk faster.
         if (h * rb2d.velocity.x < maxWalking)
             rb2d.AddForce(Vector2.right * h * moveForce);
         // Are we walk faster than full speed? Slow down Sonic!!
         if (Mathf.Abs(rb2d.velocity.x) > maxWalking)
             rb2d.velocity = new Vector2(Mathf.Sign(rb2d.velocity.x) * maxWalking, rb2d.velocity.y);
  
         // Double Tap to Run
         bool doubleTapRight = false;
         #region doubleTapRight
         if (Input.GetButtonDown("Horizontal"))
         {
             if (Time.time < doubleTapTime + .5f)
             {
                 doubleTapRight = true;
             }
             doubleTapTime = Time.time;
         }
         #endregion
  
         if (doubleTapRight)
         {
             Debug.Log("I am activating.");
             anim.SetFloat("Speed", Mathf.Abs(h));
  
             // Are we running at full speed? If not, run faster
             if (h * rb2d.velocity.x < maxRunning)
                 rb2d.AddForce(Vector2.right * h * moveForce);
             // Are we running faster than full speed? Slow down Usain Bolt!!
             if (Mathf.Abs(rb2d.velocity.x) > maxRunning)
                 rb2d.velocity = new Vector2(Mathf.Sign(rb2d.velocity.x) * maxRunning, rb2d.velocity.y);
         }


Any help would be super appreciated! Thanks in advance :)

Comment
Add comment · Show 2
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 JScotty · Nov 03, 2016 at 08:41 AM 0
Share

according to this: http://stackoverflow.com/questions/3151722/code-regions-not-allowed-within-method-bodies-in-vb-net

The problem can might be with the region if you are using an older verion of Visual studio.

You can might try to remove the double tap region to check if it works, or a simple Debug.Log within the input.getbuttondown("horizontal");

avatar image Paceytron JScotty · Nov 03, 2016 at 11:39 AM 0
Share

Hey JScotty, thanks for the quick reply! :)

So, I placed the Debug.Log within the region, tested, and removed the region, tested again. The Log returns a result on a single tap which is interesting as the old Debug that's in the code above returns on the double tap.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AngryKiwiArts · Nov 03, 2016 at 12:10 PM

this looks like remnants of an era long passed from DataLohr https://forum.unity3d.com/threads/single-tap-double-tap-script.83794/#post-1401444

try separating the double tap code and see if you can get the bool to change.

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 Paceytron · Nov 03, 2016 at 12:30 PM 0
Share

Hey Angry$$anonymous$$iwiArts, Yeah, I've tried adapting DataLohr's code from that exact thread. So, I've separated the code and the debug still triggers but I'm beginning to wonder if it's how I've set up motion for the controller.

The controller limits the speed of the character if he is traveling too fast. Perhaps, the initial maxWalking is interfering with the double tap?

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

252 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

Related Questions

Remember position for a simple player controller (Left/Right)? 0 Answers

Smooth No Gimbal Lock Analogue Rotation 1 Answer

How would do I play a walking animation when i move my joystick? 0 Answers

How can we control two player objects at one time with RayCasting? 1 Answer

oculus go movement 0 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