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
1
Question by Kac26 · Jan 19, 2015 at 11:36 AM · tagpositioninggyroscope

Gyroscope default position

I have a question about gyroscope delault position. I created a game in witch you move space ship foward, back, left, and right by moving the phone(using gyroscope). My problem is that I must hold phone like on picture 1. If i hold the phone like on picture 2, the ship goes down. Anyone know how to change default position of the gyroscope, so I can normally hold the phone and steering the ship? I want the ship stationary if my phone is holded at 45 degrees. Otherwise, it move to the titled direction.

alt text

My code:

using UnityEngine; using System.Collections;

[System.Serializable] public class Boundaryy { public float xMin, xMax, zMin, zMax; }

public class PlayerControll1 : MonoBehaviour { public float speed; public float tilt; public Boundaryy boundary;

 // Use this for initialization
 void Start () {
     Input.gyro.enabled = true;
     Screen.sleepTimeout = SleepTimeout.NeverSleep;
 }
 
 
 
 
 void FixedUpdate() {
     float xi = Input.gyro.userAcceleration.x;
     float yi = Input.gyro.userAcceleration.y;
     
     Vector3 movement = new Vector3 (xi, 0.0f, yi);
     rigidbody.velocity = movement * speed;
     
     rigidbody.position = new Vector3 
         (
             Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax), 
             0.0f, 
             Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)
             );
     
     rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
     
     
 }
 
 
 

}

zajeta slika.jpg (23.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 hav_ngs_ru · Jan 19, 2015 at 03:47 PM

 ...
 Vector3 movement = new Vector3 (xi, 0.0f, yi);
 
 movement = Quaternion.AngleAxis(45, Vector3.right) * movement; // <<< ADD THIS
 
 ...

EDIT: just corrected my silly mistake :)))

Comment
Add comment · Show 6 · 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 Kac26 · Jan 19, 2015 at 04:11 PM 0
Share

Nah, not working. The ship don't go down to the bottom.

I want the ship stationary if my phone is holded at 45 degrees. Otherwise, it move to the titled direction. If you know what I mean :)

avatar image hav_ngs_ru · Jan 19, 2015 at 04:17 PM 0
Share

arrrh! sorry, my silly mistake :)) try new code (edited in original answer)

avatar image Kac26 · Jan 19, 2015 at 04:38 PM 0
Share

Tryed it and it's still not working... $$anonymous$$y space ship is unfortunately not standing still at 45 degrees, but again in 0 (like Picture 1)...

avatar image hav_ngs_ru · Jan 20, 2015 at 10:37 AM 0
Share

have you placed it before **rigidbody.velocity = movement speed;* ?

avatar image Kac26 · Jan 20, 2015 at 11:07 AM 0
Share

I did and it just don't work :(

Show more comments
avatar image
0

Answer by MarlonH · Jan 20, 2015 at 11:28 AM

Change the local rotation with the gyro and set this object to a parent. Use the global rotation of the object :)

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 Kac26 · Jan 20, 2015 at 01:58 PM 0
Share

And how do I do that?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

View an array of the transform position/rotation of all game objects with a specified tag., 0 Answers

How read tag in the animator? 0 Answers

FindGameObjectWithTag failing 1 Answer

OnTriggerEnter Glitch 1 Answer

Tag list emptied!? 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