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 /
  • Help Room /
avatar image
0
Question by Maskimus · Jan 12, 2016 at 06:54 PM · gameaxishow

How to change Steer angle on Horizantal axis to left/right for Touch screen

basically I'm adding touch screen support for my game and want the wheels on my car to turn based on which side of the screen is pressed, the issue im having is splitting the horizontal axis into left / right to correspond with which side of screen is pressed.

i tried changing float steer too - "float steer = Input.GetAxis("Horizontal") < 0;" to provide me a "Left" i could then translate into touch but you cant do that with a float.

Any help much appreciated thanks.

 void FixedUpdate(){
 if (Input.touchCount > 0)
         {
             var touch = Input.touches[0];
             if (touch.position.x < Screen.width/2) // left side
             {
                 float steer = Input.GetAxis("Horizontal");   // this needs to know to go in the left direction
 
                 float accelerate = Input.GetAxis ("Vertical"); 
 
                 float finalAngle = steer * 45f;  
                 wheelColliders [0].steerAngle = finalAngle; // turns left wheel
 
                 wheelColliders [1].steerAngle = finalAngle; // turns right wheel
 
 
 
                 for (int i = 0; i < 4; i++) {
                     //wheelColliders[i].motorTorque = accelerate * maxTorque;
                     wheelColliders [i].motorTorque = maxTorque;
                 }
         
             
             }


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 vintar · Jan 12, 2016 at 09:06 PM 0
Share

Since you already know whether you should turn them left or right ala :

 if (touch.position.x < Screen.width/2) // left side

couldn't you simply just set the rotation to -45 or 45 accordingly ?

avatar image Maskimus vintar · Jan 12, 2016 at 09:30 PM 0
Share

@vintar i'm not sure i understand, both wheels turn together (as its a car). i use the axis.horizontal to turn both wheels together when i press "a or d"(left or right).

if i was to set it to rotate to -45 or 45 it would instantly lock the wheel in that direction? where as currently it turns the wheels depending how long you press the button(atleast that's how it feels).

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

change gravity 1 Answer

Issue with loading scenes with buttons 1 Answer

What am I doing wrong? 0 Answers

How to make ball launch in direction of line when dragged back and released?,Drag your mosue back and a line points at where youre aiming and upon letting go it slingshots in that direction 0 Answers

Expanding onto the 2D RougeLike Game adding a main menu (URGENT! help required please) 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