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 /
avatar image
0
Question by unity_54MEEm5ggbR8jg · May 11, 2020 at 08:21 AM · camerarotationcontrolgyroscopeinverted

Why the control with gyroscope inverted when I make 180 degrees turn?

Dear all

Newbie here...I've been developing a clone of Super Monkey ball which you controlled a sphere with character inside with gyroscope. I make the camera always sits behind the character with below script. However every time I make 180 degrees turn, the left, right, up, and down control becomes inverted & if I make another 180 degrees turn, the control will come back normal. Need help how to solve this issue. Thanks.

My CameraFollow script:

 using UnityEngine;
 using System.Collections;
 
 public class CameraFollow : MonoBehaviour {
 
     public GameObject target;
     public float speed = 5;
 
     Vector3 offset;
 
     void Start()
     {
        
                 offset = target.transform.position - transform.position;
             
     }
 
     void LateUpdate()
     {
         
                 // Look
                 var newRotation = Quaternion.LookRotation(target.transform.position - transform.position);
                 transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, speed * Time.deltaTime);
 
                 // Move
                 Vector3 newPosition = target.transform.position - target.transform.forward * offset.z - target.transform.up * offset.y;
                 transform.position = Vector3.Slerp(transform.position, newPosition, Time.deltaTime * speed);
            
     }
     
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by frilanski · May 22, 2020 at 05:06 PM

I'm not sure I follow what's wrong but looking at your script you're moving your camera independently to your ball and hoping the ball stays in frame. The two appear to be disconnected. I wrote this script for a car game to make the camera soft follow the car:

     void Update()
     {
         transform.LookAt(Car);
         transform.position = Vector3.SmoothDamp(transform.position, target.position, ref velocity, SmoothTime);
     }

'Car' is a public transform which appears in unity. This means you can assign the car (or in your case the ball) to the variable, so in this script 'Car' is the position of the car. 'target' is another transform which is an empty I attached to the car which is a point behind it where I want the camera to sit. In your case the ball is rotating so this point would rotate with it. So if I were you I would make this a global point behind the ball. just take the transform in the 'Car' variable and modify it to get a point behind the ball where you want the camera to sit.

Comment
Add comment · Show 3 · 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 unity_54MEEm5ggbR8jg · May 23, 2020 at 07:40 AM 0
Share

Hi @frilanski, Thank you for your answer. However I'm still experiencing the same issue after adopting your solution.

avatar image frilanski unity_54MEEm5ggbR8jg · May 23, 2020 at 09:43 AM 0
Share

Is this actually your camera script that is the issue then? Is it not your ball movement? It could be if your ball move is adding force in the balls local 'forward' etc. then that forward direction stays relative to the ball and when upside down, forward is backwards.

If that's the issue, try adding torque ins$$anonymous$$d of force to make the ball roll ins$$anonymous$$d of pushing the ball.

avatar image unity_54MEEm5ggbR8jg frilanski · May 24, 2020 at 08:56 AM 0
Share

Hi @frilanski, yeah I think it's because of my ball movement. But still can get it solved as I wanted untill now. Shared to you my ball controller script:

 public void FixedUpdate() 
     {
                 Vector3 fromCameraTo$$anonymous$$e = transform.position - mainCamera.transform.position;
                 fromCameraTo$$anonymous$$e.y = 0;
                 fromCameraTo$$anonymous$$e.Normalize();
                 float moveHorizontal = Input.GetAxis("Horizontal");
                 float moveVertical = Input.GetAxis("Vertical");
                 Vector3 movement = (fromCameraTo$$anonymous$$e * moveVertical + mainCamera.transform.right * 
                 moveHorizontal) * accelFactor * 2;
                 rb.AddForce(movement * accelFactor * 2);
     }

   

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

193 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

Related Questions

How to make camera position relative to a specific target. 1 Answer

Keyboard Controlled Overhead Camera Rotation 0 Answers

Rotate gyroscope-based camera over it's Y axis by swiping 2 Answers

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

MouseOrbit script in alternate space 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