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 IndieHood · Jul 28, 2013 at 04:18 AM · javascriptmovementslowmotion

Slow-Motion and Speed Boost - Jerky Movement Once Energy is Finished

I have my character moving on the y and x in a 2D game, my character is currently just a cube for prototyping reasons.

I have a sprint effect and a slow-motion effect, these are both activated by a button press, both last for a certain amount of time and then get regenerated for reuse.

I have got the general setup to a good level but when my slow-motion or sprint energy stores run out the movement does not entirely go back to normal if you don't release the buttons, slow-motion and sprint still has a slight effect on the characters movement.

Would be very grateful if someone could point me in the right direction:

My code is a bit messy so apologies!

 public var xspeed : float = 24; 
 public var yspeed : float = 24; 
 var x : float; 
 var y : float;
 var slowMotionBurnSpeed : float;
 var haveSlowMotion : boolean;
 var slowMotionAmount : float;
 var slowMotionRegenRate : float;
 var slowMotionMax : float;
 var slowMotionMin : float;
 var sprintBurnSpeed : float;
 var havesprint : boolean;
 var sprintAmount : float;
 var sprintRegenRate : float;
 var sprintMax : float;
 var sprintMin : float;
 public var sprintTex : Texture;
 
 function Start ()
 {
         haveSlowMotion = true;
         havesprint = true;
 }
 
 function Update () { 
 
 // *********** Sprint Button
 
 if ((Input.GetKey ("escape")) && (sprintAmount > sprintMin))
 
 {
 
 xspeed = 50;
 yspeed = 50;
 sprintAmount -= (sprintBurnSpeed*Time.deltaTime);
 
 
 }
 
 else 
 
 {
 xspeed = 24;
 yspeed = 24;
 }
 
 
 
 // *********** General Movement 
 
 x = Input.GetAxis("Horizontal") * xspeed * Time.deltaTime; 
 y = Input.GetAxis("Vertical") * yspeed * Time.deltaTime; 
 transform.Translate(x, y, 0); 
 
 
 // *********** SLow Motion 
 
 if (haveSlowMotion)
 
 {
 
 
     if (Input.GetKey ("space")) // Slow Motion
     
             {
             
             if (slowMotionAmount > slowMotionMin)
                 {
                 Time.timeScale=0.15; 
                 slowMotionAmount -= (slowMotionBurnSpeed*Time.deltaTime); 
                 }    
 
         // Ran out of slowMotion charge
     else 
         {
             slowMotionAmount = 0;
             haveSlowMotion = false;
             Time.timeScale = 1;
         }
         
 }
 }
     
 //******** Returning out of slowmotion
     
 if (Input.GetKeyUp("space"))
 
     {
     
     
     Time.timeScale = 1;
     
     }
 
 //******* power ups and true and false
 
 if (slowMotionAmount <= (slowMotionMax))
         
     {
     slowMotionAmount += (slowMotionRegenRate);
     }
     
 if (slowMotionAmount >= (slowMotionMin))
     {
     haveSlowMotion = true;
     }    
     
 if (sprintAmount <= (sprintMax))
         
     {
     sprintAmount += (sprintRegenRate*Time.deltaTime);
     }
     
 if (sprintAmount >= (sprintMin))
     {
     haveSlowMotion = true;
     }        
 
 
 }
 
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
Best Answer

Answer by Jamora · Jul 28, 2013 at 04:24 AM

Increase the sprintMin and slowMotionMin amounts so that you don't allow for them if the player has 0.01 energy out of 100. This causes the jerkiness in movements. Force the player to regen a set amount before allowing the use again. A lot of big games do this too.

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 IndieHood · Jul 28, 2013 at 09:43 AM 0
Share

Thanks Jamora,

That makes sense now thinking about it!

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

16 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

Related Questions

Slowing Down When Sliding Across Walls 2 Answers

Horizontal axis not working after animation 1 Answer

I am trying to make a movement script for my main camera but it isnt working! 2 Answers

Move Object Smoothly 1 Answer

Rigidbody.MovePosition doesn't move reliably? 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