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
1
Question by katielawrence36 · Dec 26, 2016 at 03:45 PM · xbox360

how do I add a non linear curve to an axis input

I have a steering input that I want to make non-linear, so with more lock the turn rate increases.

It is based on an xBox controller, currently this is on a input.getaxis which is multiplied by a speed constant and then clamped between -1 and 1.

Could I increase the speed for a certain angle or can I map it to a curve?

Thank you

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by AlwaysSunny · Dec 26, 2016 at 04:49 PM

I have found that the easiest way to work with curves with native Unity is the AnimationCurve type.

 public AnimationCurve myAnimationCurve;

This may not always satisfy every need, but it sounds appropriate for your stated requirement. Design the curve in the inspector, or optionally build or edit the curve handles at runtime with the API.

The argument used to evaluate your current position on the curve expects a normalized value (zero-to-one range). This can be derived from whatever variable you like, such as the normalized percentage of "lock" your vehicle is experiencing.

 // assumes lock is positive and minimum lock is zero
 float lockPercentage = myCurrentLockValue / maximumLockValue;
 float steeringSensitivity = myAnimationCurve.Evaluate( lockPercentage );
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 katielawrence36 · Jan 03, 2017 at 05:42 PM 0
Share

Thank you for this - I'm still trying to work out how to add the animation curve lol

I need to be able to have a negative valu e(steering left to right for example) - will this still work?

avatar image AlwaysSunny katielawrence36 · Jan 03, 2017 at 06:32 PM 0
Share

When you declare a variable whose type is AnimationCurve as public, it'll expose it in the inspector. You can click this field to open Unity's graph editor. It's not the best one in the world, but I'm sure you can create the kind of curve you need, including negative values.

When you read from that curve with your call to myAnimationCurve.Evaluate(), your argument tells Unity where along the curve to read from. The left of the curve corresponds to an argument of zero, the right corresponds to one, and all points in between. Check out the AnimationCurve documentation for more details. :)

avatar image
0

Answer by katielawrence36 · Jan 19, 2017 at 12:07 AM

Hello

I added the following code:

     SteerAngle = Input.GetAxis("Wheel") * 0.08f;
     SteerAngle = Mathf.Clamp(SteerAngle, -1.0f, 1.0f);

     //Code added by KL as a test
     float SteeringSensitivity = SteeringCurve.Evaluate(SteerAngle);

As well as the public AnimationCurve SteeringCurve

I am debugging in unity now but it still does not work. I created the attached curve.

Any ideas much appreciated :-)

Thank youalt text

,Hi

I added the

public AnimationCurve SteeringCurve;

and the following code

     SteerAngle = Input.GetAxis("Wheel") * 0.08f;
     SteerAngle= Mathf.Clamp(SteerAngleAngle, -1.0f, 1.0f);

     //Code added by KL as a test
     float SteeringSensitivity = SteeringCurve.Evaluate(SteerAngle);

And also the attached curve. I'm currently debugging in Unity but the xBox controller input for steering no longer seems to work, have I missed something?

Thank youalt text


steering-curve.jpg (66.0 kB)
steering-curve.jpg (66.0 kB)
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 osamansr2o1oo · Oct 04, 2018 at 10:16 AM 0
Share

did this work with u ?

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Control object (character) rotation with 360 analogue. 1 Answer

Input manager is conflicted, help? 0 Answers

Xbox 360 gamepad numbers mixed up 0 Answers

3rd Person Free Roam...Where to Start? 1 Answer

How do you publish your game? 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