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 skylerkingdev · Oct 25, 2012 at 05:31 AM · iosrotatesmoothaccelerometer

How to rotate your device and counter rotate camera

I'm looking to use accelerometer input to influence game objects, but counter rotate the camera so the scene always stays flat on the horizon. Sort of like asphalt7 and real racing. I have tried a few things but they are all so jittery that it seems like I have frame rate issues. I found this out on the forums somewhere and it gets pretty close but is still not smooth enough.

 function Update () {
 
 var finalAngle = Input.acceleration.y*90;
 
 transform.localEulerAngles.z = finalAngle;
 
 }

Is there a better way to go about this? Or how would one go about smoothing the above enough to make things look good?

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 prototype7 · Oct 25, 2012 at 06:09 AM 0
Share

did you try use smooth damp ?

 fuction Update(){
     var finalAngle = Input.acceleration.y * 90;
     var smoothTime : float = 0.3F;
     private var myVelocity : float = 0.0F;
     
     var newPosition : float = $$anonymous$$athf.SmoothDamp(transform.localEulerAngles.z, finalAngle, myVelocity, smoothTime);
     transform.localEulerAngles = Vector3(transform.localEulerAngles.x, transform.localEulerAngles.y, newPosition);
 }


avatar image skylerkingdev · Oct 25, 2012 at 11:55 PM 0
Share

Thank you for the reply. The issue that I am running into with that is the camera is rolling completely over. Like a barrel roll. Im trying to limit it. It is strange because it only does that when I tilt to the left.. the right is fine. The smooth damp does help it out as far as animation goes. It looks really nice in motion. It seems like when the z rotation hits 0 it rolls completely over. Hmm.

avatar image skylerkingdev · Oct 26, 2012 at 02:40 AM 0
Share

Okay, I have a pretty good solution for getting this working, but I'm not sure the smooth damp is working at all. Have a look at this

var myVelocity : float = 0.0F;

var lookSmoothDamp : float = .3;

function Update () {

 var finalAngle = Input.acceleration.x*40*-1;

 var cameraRotation = $$anonymous$$athf.SmoothDamp(maincamera.transform.rotation.z, finalAngle, myVelocity, lookSmoothDamp);

 

 if(finalAngle < 20 && finalAngle > -20) {

 maincamera.transform.localEulerAngles.z = cameraRotation;

 }

}

avatar image prototype7 · Oct 27, 2012 at 12:01 AM 0
Share

You can try put in your code inside LateUpdate, that will track your object more precisely

avatar image shane.rachel · Dec 13, 2012 at 05:57 AM 0
Share

multiply finalAngle by Time.deltaTime and play with the number 90 (increase/decrease it to what you need)

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

11 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

Related Questions

Limit rotation from another script 0 Answers

How to create tilt control similar to temple run? 0 Answers

Why is the Gyroscope inverted? 0 Answers

Rotating a character smoothly 0 Answers

How can i make my aircraft rotate as smooth as the one in race the sun, and then go back to its original position 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