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 /
avatar image
0
Question by rohan bhangui · Oct 06, 2011 at 12:21 AM · boost

need help with a boost effect

i want to make a boost effect when i press a desired key (in my case left alt)....The thing is I want to do it i nthe same script how would i do it based on these lines of code

 if ((groundtrigger.triggered==0)&&(Input.GetButton("Fire1"))&&(speed<800)) speed+=Time.deltaTime*240;
         if ((groundtrigger.triggered==0)&&(Input.GetButton("Fire2"))&&(speed>600)) speed-=Time.deltaTime*240;
         if ((groundtrigger.triggered==0)&&(Input.GetButtonDown("Boost"))&&(speed<800)) transform.Translate(0,0,speed*Time.deltaTime*10);

please tell me if you require more code (for reference)

what i want to do is make the object boost and then it slows down smoothly

can you help me?

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 syclamoth · Oct 06, 2011 at 01:28 AM 0
Share

You could have a 'currentBoost' variable, which goes down by some multiple of Time.deltaTime every frame. When you want to activate the boost, press your key and set it to something high, and then multiply all your speed variables by the current boost. Also, use $$anonymous$$athf.Clamp to make sure the boost never goes below a certain number- make sure you don't have negative boost, making you go backwards!

avatar image rohan bhangui · Oct 06, 2011 at 03:09 AM 0
Share

could you maybe code it out slightly in an example ....because thats how i usually grasp a concept.....by seeing example code

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Tseng · Oct 06, 2011 at 01:37 AM

Well, you need different variables, like currentSpeedand speed and interpolate it, and always only update speed variable.

 if ((groundtrigger.triggered==0)&&(Input.GetButton("Fire1"))&&(speed<800)) speed+=Time.deltaTime*240;
 if ((groundtrigger.triggered==0)&&(Input.GetButton("Fire2"))&&(speed>600)) speed-=Time.deltaTime*240;

 currentSpeed = Mathf.Lerp(currentSpeed, speed, Time.time * smoothSpeed),
 if ((groundtrigger.triggered==0)&&(Input.GetButtonDown("Boost"))&&(speed<800)) transform.Translate(0,0,currentSpeed*Time.deltaTime*10);

This will smooth both, acceleration as well as deceleration...

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
avatar image
0

Answer by rohan bhangui · Oct 06, 2011 at 11:39 AM

okay great......i found the solution.......

i added this line of code

     if ((groundtrigger.triggered==0)&&(Input.GetButton("Boost"))&&(speed<800)) transform.Translate(0,0,speed/200);

this allows me too boost......all i have to wrry about is smoothing it out........thx all :)

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 Tseng · Oct 06, 2011 at 12:07 PM 0
Share

This is no forum, only answers to the questions are posted there, everything else goes into the comments: Read the FAQ: http://answers.unity3d.com/page/faq.html

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Getting audio.PlayOneShot to work 2 Answers

Projector Toggling - Scripting Problem 1 Answer

I need Help With a Speed up script 1 Answer

Yield function goes slow sometimes/differently? 2 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