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 /
This question was closed Feb 14, 2019 at 02:23 PM by Nosmo for the following reason:

Other

avatar image
0
Question by Nosmo · Feb 13, 2019 at 05:04 PM · movementaxiscontrolgyroscopegyro

Gyroscope Controls for FPS

I've made a small fps for android and looking round is done with Gyroscopic control, but when i move I only move forward along the X axis, no matter what direction I'm looking in.

Any suggestions as to how I can fix this?

player movement

 CharacterController charControl;
 public float Speed = 2f;
 float hor; //addition
 float ver; //addition

 public Joystick joystick; //addition

 void Awake () {
     charControl = GetComponent<CharacterController>();
 }
 
     void Update () 
 {
     MovePlayer();
 }

 void MovePlayer()
 {
     hor = joystick.Horizontal; //addition
     ver = joystick.Vertical; //addition

     Vector3 moveDirSide = transform.right * hor * Speed;
     Vector3 moveDirForward = transform.forward * ver * Speed;

     charControl.SimpleMove(moveDirSide);
     charControl.SimpleMove(moveDirForward);
 }

gyro:

 private bool gyroEnabled;
 private Gyroscope gyro;

 //private GameObject cameraContainer;

 private Quaternion rot;

 private void Start()
 {
     //cameraContainer = new GameObject ("Camera Container");
     //cameraContainer.transform.position = transform.position;
     //transform.SetParent (cameraContainer.transform);

     gyroEnabled = EnableGyro();
 }

 private bool EnableGyro()
 {
     if (SystemInfo.supportsGyroscope)
     {
         gyro = Input.gyro;
         gyro.enabled = true;

         //cameraContainer.transform.rotation = Quaternion.Euler (90f, 90f, 0f);
         rot = new Quaternion (0, 0, 1, 0);

         return true;
     }

     return false;
 }

 private void Update()
 {
     if (gyroEnabled) 
     {
         transform.localRotation = gyro.attitude * rot;
     }
 }

}

Comment
Add comment · Show 2
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 xxmariofer · Feb 13, 2019 at 07:15 PM 0
Share

you need to share your code for us to help you.

avatar image xxmariofer · Feb 14, 2019 at 01:31 PM 0
Share

hello, can you debug.log transform.forward in the playercontroller scipr inside the update and make sure it is changing? also you should be calling simplemove only once per frame consider mixing the horizontal and vertical lines, but this should be your issue. the gyro and the player script are in the exact same gameobject right? not in childs?

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

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

Moving.Rotating a Raycast with Respect to Rotation 1 Answer

Can't move player with this code why?,I cannot move my player with this code why? 0 Answers

Im trying to make a player move 360 degree gyroscopic movement on my phone 0 Answers

How to add random force on x axis for a moving object? 0 Answers

How to make a 2D rigidbody vertically when input is via the gyroscope 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