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 24, 2013 at 01:07 AM · javascripttimescaleslowmotion

Decreasing and increasing a SlowMotion powerup

I have created a very rudimentary slow motion ability in my game but I don't want it to be able to be used at all times.

The solution I have in my head the idea is to have a SlowMotionCredit bank which depletes with usage at a fast rate and then slowly replenishes itself.

The following code is attached to the 'player' but once I add the SlowMotionCredit related lines the script compiles on but the slowmotion then doesn't work.... Interesting to hear people's thoughts... cheers

 var xspeed : float = 5; 
 var zspeed : float = 5; 
 var x : float; 
 var z : float;
 
 public var SlowMotionCredit : float = 60; // SlowMotionCredit Initial starting figure
 
 function Update () { 
 
 x = Input.GetAxis("Horizontal") * xspeed * Time.deltaTime; 
 z = Input.GetAxis("Vertical") * zspeed * Time.deltaTime; 
 transform.Translate(x, 0, z); 
 
 SlowmotionCreditUpdate() {
 
  SlowMotionCredit +1; // replenish SlowMotionCredit at a rate of 1 per second
  
 }
 //SlowMotion Starts
 
 if (Input.GetKeyDown ("space"))
     Time.timeScale=0.15;
     SlowMotionCredit - 12; // Deducting 12 Credits for each second of SlowMotion Time Spent
     
 //Time resets
 if (Input.GetKeyUp ("space"))
     Time.timeScale=1;
 }
Comment
Add comment · Show 1
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 24, 2013 at 01:07 AM 0
Share

I will have to add a if statement 22 to first check if the Slow$$anonymous$$otionCredit bank is greater than 0.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by chris_taylor · Jul 24, 2013 at 01:30 AM

first off there is no {} on the

 if (Input.GetKeyDown ("space"))
     Time.timeScale=0.15;
     SlowMotionCredit - 12; // D

So SlowMotionCredit -= 12 would get called every Update. What you need to do is change it to this

 if (Input.GetKeyDown ("space") && SlowMotionCredit >= slowMoCost)// use a variable for cost that way its easy to edit
 {
     Time.timeScale=0.15;
     SlowMotionCredit -= slowMoCost; // D
 }

You should also add that to the Fixed update that way it lowers based off time and not how fast the FPS is

Comment
Add comment · Show 2 · 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 24, 2013 at 06:29 AM 0
Share

Chris - thanks for your help! It's getting closer!

Unfortunately it deducts the Slo$$anonymous$$oCost once irrespective of how long the player holds the space bar to stay in slo$$anonymous$$o mode.

     if (Input.Get$$anonymous$$eyDown ("space") && Slow$$anonymous$$otionCredit > 0)// use a variable for cost that way its easy to edit
     {
         Time.timeScale=0.15;
         Slow$$anonymous$$otionCredit -= slow$$anonymous$$oCost; // D
         
     }

Is there anything you can suggest to make it deduct the cost for every second in slo$$anonymous$$o mode not the amount of times?

Cheers!

avatar image chris_taylor · Jul 24, 2013 at 09:02 AM 0
Share

@IndieHood Your welcome, im here to help. change it to Input.Get$$anonymous$$ey ins$$anonymous$$d of Input.Get$$anonymous$$eyDown and that should help with that problem as Get$$anonymous$$eyDown only returns true when you first push the button down and Get$$anonymous$$ey returns true anytime the key is down

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

Calcule Player's Speed based on Time.timeScale 1 Answer

Time.timeScale = 0 did not prevent click 1 Answer

How would you find out if a rotation is between two values? 2 Answers

Help with my "speeding up time" script 1 Answer

Slow-Motion and Speed Boost - Jerky Movement Once Energy is Finished 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