Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 KhShani · Aug 08, 2014 at 10:48 AM · cameraiphonetouchrotate

Rotate camera smoothly to certain degrees with iphone touch

I'm trying to emulate the "swipe to look" controls found in iPhone games such as Dead Trigger (made in Unity), Modern Combat and Minecraft, in that swiping your finger rotates the camera to your fingers' position, then stops. I've tried using both the mouselook script and various joysticks/joypads positioned in the center of the screen and set to invisible but none of them have the "stopping" affect (if you hold your finger down the camera will spin in circles until you let go). I therefore have two questions: 1) Are there any existing control mechanisms that emulate this style (I'm willing to pay) 2) If not, how would I go about achieving this effect? EDIT: I do not mean joystick controls. A joystick will rotate indefinitely in a certain direction until touch ends. These games rotate to a certain point then STOP, regardless of whether touch is maintained or not. The best way to experience this is to download "Minecraft Lite" or "Dead Trigger", both are free, but this mechanic seems to be fairly prevalent throughout iPhone FPSes. Others off the top of my head are the Gameloft games ie Modern Combat, Eden World Builder and Marathon. Here is a video of the dead trigger controls: https://www.youtube.com/watch?v=PRW01ygkmuE Eden Worldbuilder: http://www.youtube.com/watch?v=XaqGVfbB8B4

Comment
Add comment · Show 5
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 robertbu · Aug 08, 2014 at 11:47 AM 0
Share

Given an identified touch, it seems to me that all they are doing is:

  var yRotate = -touch.deltaPosition.x * factor / Screen.height;
  var xRotate = touch.deltaPosition.y * factor / Screen.height;
  transform.Rotate(xRotate, yRotate, 0.0);

The division by screen height is a basic way to making the movement somewhat consistent across different devices. They may be using Screen.dpi ins$$anonymous$$d.

avatar image KhShani · Aug 08, 2014 at 01:51 PM 0
Share

thanks that works.

avatar image KhShani · Aug 08, 2014 at 01:51 PM 0
Share

But What if also want to restrict my angles to restrict ?????

avatar image HarshadK · Aug 08, 2014 at 01:55 PM 0
Share
  • Limit local rotation

  • Clamping a wrapping rotation

avatar image Fianna Entertainment · Feb 14, 2016 at 11:02 PM 0
Share

Would someone be able to explain to explain this in a bit more detail please?

Thanks in advance.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Aug 08, 2014 at 02:45 PM

But What if also want to restrict my angles to restrict ?????

Maintain your own class instance Vector3. Something like this:

 private var angles : Vector3 = Vector3.zero;

Then the code would be:

  angles.x += touch.deltaPosition.y * factor / Screen.height;
  angles.y += -touch.deltaPosition.x * factor / Screen.height;
  angles.x = Mathf.Clamp(angles.x, -45.0, 45.0);
  transform.eulerAngles = angles;

The code clamps the 'x' rotation between -45 and 45 degrees.

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

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

22 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

Related Questions

2D Camera (Android, Iphone) 1 Answer

how to rotate 3d model in touch using guy texture object 1 Answer

rotate object to touch position 1 Answer

iphone camera rotation by touch 4 Answers

touch to move camera, scroll over level 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