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 oliver-jones · Aug 13, 2013 at 08:55 PM · camerarotationiosscenegyro

Transform Rotation - Maths Problem

Hello,

I'm trying to figure out a rotation problem here.

My scene camera rotates by using my iOS gyro (on an X, Y, Z and W axis)- so basically, if I rotate my phone around my physical room, the game scene will also be 'copying' my rotations on the scene camera.

Now, what I have is a 'hand' model as a child, within the camera, so it rotates with the camera - so it looks like it never rotates to the viewer of the camera.

Hear me out - when I rotate the actual device sideways (Z axis), I want the hand model to always stay the correct way up. Let me do an illustration (It's hard to explain):

alt text

^ This is what I WANT to happen. Right now - the hand just stays at the default orientation (But still moves with the camera, so its always in view, in front of the camera).

All thats changing my camera rotation is this:

 rotFix = Quaternion(0,0,1,0);
 var camRot : Quaternion = gyro.attitude * rotFix;
 transform.localRotation = camRot;

Any ideas how I can achieve this with my hand? Thanks!

--- EDIT ---

A good example I found on the app store is a game called AR Zombies - When you hold the device and rotate around your actual room, the game moves with your rotation (This is already working fine). But, if you rotate your device sideways (left and right), notice how the character (weapon) is always dynamically at the bottom (it rotates with the device).

ss.jpg (149.2 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Wuzseen · Aug 13, 2013 at 10:08 PM

I believe you could achieve the effect you're searching for by putting your hand on one layer and drawing it with a separate camera.

So you would have a new hand layer and a new camera. The camera would be set to just drawing that hand layer. Your main camera would be set to drawing everything but that hand--as well as set to depth only. Depth only being a clear flags option.

This is a common method for using elements in 3D space as GUI elements though it's also a popular option for drawing hands and what not to the main camera so that is separate from that camera's rotation in some respects.

The effect is that the hand is now constantly drawn to the screen in a static position while the rest of the world moves fine.

EDIT: I reread your question and understand it a bit better now. In which case I don't believe what I typed above will be the solution you're looking for--I will leave it up there as it is still tangentially related. You could always define the behavior of the hand in a script so that it mimicks the motion you want it to. It doesn't have to be a child of your camera--which is the only way, save for a script, it would inherit the rotation of your camera.

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 oliver-jones · Aug 14, 2013 at 08:11 AM 0
Share

Thanks for the reply - although I don't think this will achieve the affect I'm looking for - The hand wont rotate/move with the camera. It needs to move with the camera in sync. It's really hard for me to explain.

A good example I found on the app store is a game called AR Zombies - When you hold the device and rotate around your actual room, the game moves with your rotation (This is already working fine). But, if you rotate your device sideways (left and right), notice how the character (weapon) is always dynamically at the bottom (it rotates with the device).

avatar image Wuzseen · Aug 14, 2013 at 12:23 PM 0
Share

I think I get it--you want it to be more like a head and your hand follows you as if its part of your body.

In that case I see two options. Roll your own script that calculates the deltas of position of the main camera and then move your hand a factor of that delta each frame. Alternatively you can use Vector3.lerp in a semi different than usual way, this code would sit on your hand:

  transform.position = Vector3.Lerp(transform.position, Camera.main.transform.position, .8);

I haven't had the chance to test it, but this should keep your hand moving 80% of the distance the camera has. $$anonymous$$ore to the point, it simply follows its position rather than rotate with it.

avatar image
0

Answer by chelnok · Aug 14, 2013 at 09:37 AM

If i got it right, you need to use Quaternion.Inverse:

yourHandTransform.rotation = Quaternion.Inverse(gyroRotation);

i dunno how gyro gives you rotation info, but i'm sure your get the point.

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 meat5000 ♦ · Aug 14, 2013 at 12:41 PM 0
Share

I read that Unity automatically retrieves gyro info when you use accelerometer. The way we use the accelerometer is actually what gyro info looks like. Accelerometer in fact shows the actual acceleration of the phone in different orientations and shouldnt give you positional info at all! Weird eh?

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

18 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

Related Questions

Gyroscope smooth transitions (minimizing jerk from tiny movements) 1 Answer

Camera behavior the same as the unity editor has 2 Answers

3D camera relatively using gyro a la N.O.V.A. 2 0 Answers

How to show live camera on android inside scene??? 1 Answer

Rotating plane from its edge 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