• 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 PlayCreatively · Aug 07, 2016 at 01:23 PM · 2dinterpolationdegreesinterpolate

Get a value that interpolates between two floats based on where character is facing

I'm making a controller script for a paper airplane and I'm currently stuck on trying to make the plane gain speed when facing down but lose speed when facing up.

The ideal way would be having a value that's 0 when facing right or left but drops to -1 when facing up and 1 when facing down (It doesn't really matter w$$anonymous$$ch is 1 or -1 just that they're distinguishable). Then I'd just multiply that value (w$$anonymous$$ch is somewhere in between -1 and 1) by gain and add that to my speed variable like t$$anonymous$$s speed += value * gain.

Here's a picture to better understand.

I already got the information where the plane is currently facing (both in vector form and degrees) but how can I do t$$anonymous$$s?

alt text

untitled-2.png (15.5 kB)
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
1

Answer by SarperS · Aug 07, 2016 at 06:36 PM

Below line would give you a value between 1 and 0. 1 when the transform looks downward with 90 degrees and 0 when directly upwards.

 var dir =  -transform.forward.y * 0.5f + 0.5f   

If you don't want to stop the plane completely when it looks upwards, instead of multiplying your movement speed value directly with t$$anonymous$$s value, I would suggest using a lerp.

 var dir =  -transform.forward.y * 0.5f + 0.5f;
 speed = Mathf.Lerp( minSpeed, maxSpeed, dir);

Comment
Add comment · Show 13 · 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 Glurth · Aug 07, 2016 at 06:43 PM 0
Share
avatar image SarperS Glurth · Aug 07, 2016 at 06:47 PM 0
Share
avatar image Glurth SarperS · Aug 07, 2016 at 06:56 PM 0
Share
avatar image PlayCreatively · Aug 07, 2016 at 07:00 PM 0
Share
avatar image SarperS PlayCreatively · Aug 07, 2016 at 07:34 PM 0
Share
avatar image PlayCreatively SarperS · Aug 08, 2016 at 01:12 PM 0
Share
Show more comments
avatar image SarperS PlayCreatively · Aug 07, 2016 at 07:43 PM 0
Share
avatar image PlayCreatively SarperS · Aug 07, 2016 at 11:44 PM 0
Share
Show more comments

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Rigidbody2D interpolation doesn't work properly 0 Answers

Mesh looks like overlapping. 0 Answers

Moving an object to a direction in degrees at a specific speed? 0 Answers

Mathf.Lerp for integers 1 Answer

converting degrees per second into speed 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