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 /
This question was closed Oct 07, 2013 at 08:30 AM by Ranger-Ori for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Ranger-Ori · Oct 01, 2013 at 02:44 PM · camerabuildorbit

Android deltaPosition.y isn't working?

I've got a weird bug in my project.

A little background, I have a joystick for movement on the left side of the screen, and I want the player to be able to rotate the camera (mouse/touch orbit) around the target using only the right side of the screen, so there would be no collision with the left joystick and the calculation of the position.

The code works great when I test in Unity Remote, but when I build it, it somewhat seems that the y position of the Mouse Orbit is locked, and I'm unable to change the height position of the camera.

Here is the code: using UnityEngine; using System.Collections;

 [AddComponentMenu("Camera-Control/Mouse Orbit with zoom")]
 public class MouseOrbit : MonoBehaviour
 {
 
     public Transform target;
     public float distance = 5.0f;
     public float xSpeed = 120.0f;
     public float ySpeed = 120.0f;
 
     public float yMinLimit = -20f;
     public float yMaxLimit = 80f;
 
     public float distanceMin = .5f;
     public float distanceMax = 15f;
 
     float x = 0.0f;
     float y = 0.0f;
 
     // Use this for initialization
     void Start()
     {
         Vector3 angles = transform.eulerAngles;
         x = angles.y;
         y = angles.x;
 
         // Make the rigid body not change rotation
         if (rigidbody)
             rigidbody.freezeRotation = true;
     }
 
     void Update()
     {
         if (target && Input.touchCount == 1 && Input.GetTouch(0).position.x > Screen.width / 2 && Input.GetTouch(0).phase == TouchPhase.Moved) //Just orbit touch without movement
         {
             Debug.Log("Orbiting! 1 touch");
             Orbit(Input.GetTouch(0));
         }
         else if (Input.touchCount == 2)
         {
             if (Input.GetTouch(0).position.x > Screen.width / 2 && Input.GetTouch(0).phase == TouchPhase.Moved)
                 Orbit(Input.GetTouch(0)); //Movement was touched second
             else if (Input.GetTouch(1).position.x > Screen.width / 2 && Input.GetTouch(1).phase == TouchPhase.Moved)
                 Orbit(Input.GetTouch(1)); //Movement was touched first
         }
 
     }
 
     void Orbit(Touch touch)
     {
         x += touch.deltaPosition.x * xSpeed * 0.02f /* * distance*/;
         y -= touch.deltaPosition.y * ySpeed * 0.02f /* * distance*/;
 
         y = ClampAngle(y, yMinLimit, yMaxLimit);
 
         Quaternion rotation = Quaternion.Euler(y, x, 0);
 
         //distance = Mathf.Clamp(distance - Input.GetAxis("Mouse ScrollWheel") * 5, distanceMin, distanceMax);
 
         RaycastHit hit;
         if (Physics.Linecast(target.position, transform.position, out hit))
         {
             distance -= hit.distance;
         }
         Vector3 negDistance = new Vector3(0.0f, 0.0f, -distance);
         Vector3 position = rotation * negDistance + target.position;
 
         transform.rotation = rotation;
         transform.position = position;
     }
 
     public static float ClampAngle(float angle, float min, float max)
     {
         if (angle < -360F)
             angle += 360F;
         if (angle > 360F)
             angle -= 360F;
         return Mathf.Clamp(angle, min, max);
     }
 
 
 }
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

  • Sort: 
avatar image
0
Best Answer

Answer by Ranger-Ori · Oct 07, 2013 at 08:29 AM

The issue was fixed, there was a collision between two scripts, MouseOrbit.js and MouseOrbit.cs, apparently there was a warning on the console which I didn't pay attention to it since I thought it was a minor issue, and as I said, the game worked just fine with Unity Remote, after creating a new script "TouchOrbit.cs" and using it only, there was no collision and the script worked excellently on the mobile device.

Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

14 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

Related Questions

Distribute terrain in zones 3 Answers

Camera performance issue 0 Answers

Cinemachine FreeLook - Explicitly setting orbit rotation 1 Answer

Game preview incorrect! 0 Answers

Camera Changes Proportions In Build 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