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 UDN_2f0abe75-257a-49c7-aaed-cdb8b48980dc · Jun 11, 2016 at 02:31 PM · c#rotation

Touch Inputs

Hi, So I have a vehicle which as a constant force applied to it. It is a 3d game, and I wish to make a system like this: alt text

When the user touches the button, I want the car to steer (i.e rotate around a point to rotate the car 90 degrees).

For example, the red points would be transform positions, and when the user presses the button, the taxi rotates around that point, depending on how long they hold the button down for. So if the user held the button down, it would rotate the taxi around that point 10 degrees, and if they held it for two seconds, it would rotate by 20 degrees.

Hope this makes sense, and would love to hear any ideas about how this could work. Thanks, @Mavina

test.png (94.4 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
0
Best Answer

Answer by Mmmpies · Jun 11, 2016 at 03:04 PM

Add an EventTrigger component to the button. Add New Event Type and select Pointer Down.

Create a script that has a public function called TurnRightBy.

Have a float PressedFor and a bool isPressed declared at the top of the script. Then in TurnRightBy set the bool to true In Update add Time.deltaTime to that float if the bool is true.

Add another New Event Type (Pointer Up) and another public function called TurnMeRight. Take the float PressedFor and round off to get your time held and apply your right rotation, set the bool to false and reset PressedFor to zero.

drag the script onto the button and in the button inspector drag the button onto the empty slots. The for Pointer Down select YourScriptName -> TurnRightBy and for PointerUp select YourScriptName -> TurnMeRight.

Do the same for the Left button but with a left turn.

Comment
Add comment · Show 8 · 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 UDN_2f0abe75-257a-49c7-aaed-cdb8b48980dc · Jun 11, 2016 at 03:37 PM 0
Share

Could your write a script? I am new to unity @$$anonymous$$mmpies

avatar image Mmmpies · Jun 11, 2016 at 04:01 PM 0
Share

This is the script I threw together to make sure I wasn't giving you duff information

 using UnityEngine;
 using System.Collections;
 
 public class RightTurn : $$anonymous$$onoBehaviour {
 
     private float PressedFor = 0f;
     private bool isPressed = false;
 
     void Update()
     {
         if(isPressed)
             PressedFor += Time.deltaTime;
     }
 
     public void TurnRightBy()
     {
         isPressed = true;
     }
 
     public void Turn$$anonymous$$eRight()
     {
         print ("Turn right by " + PressedFor);
         isPressed = false;
         PressedFor = 0f;
     }
 }

All it does is output to the console how long the button was pressed for so it doesn't actually do the rotation but it's a good idea to try it yourself, look up

http://docs.unity3d.com/ScriptReference/Transform.Rotate.html

and to round off the float value

https://docs.unity3d.com/ScriptReference/$$anonymous$$athf.Round.html

I'm sure you can do it :)

avatar image UDN_2f0abe75-257a-49c7-aaed-cdb8b48980dc Mmmpies · Jun 11, 2016 at 04:10 PM 0
Share

I will let you know - thanks! @$$anonymous$$mmpies Would I need to add an empty game object as a child of the taxi as its rotation point? What is a 'Pointer Up'.. arrgghh what do I do :/ So confused

avatar image Mmmpies UDN_2f0abe75-257a-49c7-aaed-cdb8b48980dc · Jun 11, 2016 at 04:22 PM 0
Share

Now that depends on what you want to do with the taxi. You shouldn't need to if just turning it left or right but if you start getting into complex things like in air $$anonymous$$ario $$anonymous$$art spinning then you might.

$$anonymous$$eep it simple for now just work on Rotating the Transform of your taxi.

Incidentally you will need to times that float by 10 before rounding off if you want 10 degrees in a second. You might want more than that as well as that's still 9 seconds for a full right angle turn of 90 degrees.

Show more comments
avatar image Mmmpies · Jun 11, 2016 at 04:59 PM 0
Share

Try and get the script to work on your own, the more you work on it yourself the faster you'll learn.

Take that PressedFor float and times it by 10 and round off the resulting number with $$anonymous$$ath.Round.

Then tranfrom rotate using Vector3.Right * the rounded number.

The example in those links are almost all you need. You can do this.

avatar image UDN_2f0abe75-257a-49c7-aaed-cdb8b48980dc Mmmpies · Jun 11, 2016 at 05:01 PM 0
Share

Do I need 2 scripts? @$$anonymous$$mmpies

avatar image Mmmpies UDN_2f0abe75-257a-49c7-aaed-cdb8b48980dc · Jun 11, 2016 at 05:11 PM 0
Share

You can do it with one but having an individual script for right and left isn't an issue with such a small script so yes do 2 scripts.

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

169 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 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 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 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

Rotate Sphere? 1 Answer

[VR] Make a bow follow the 'holding object' AND look at the 'string pulling hand' 1 Answer

Orienting a instanced Objects long-axis to the same point 1 Answer

Help with raycast for for wall detection 1 Answer

No Particle Rotation When Setting rotation3D from C# 0 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