Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 shruikan · Aug 28, 2015 at 12:07 PM · touch controlstouchscreenmobile deviceskeyboard inputtouchpad

KeyboardOrbit with DualTouchControls

Hi, I have problem with moving camera with KeyboardOrbit script using DualTouchControls prefab. Touchpad works great with FirstPersonCharacter (disabled when orbit camera is active), but I can't move orbit camera with touchpad even if touchpad is set to the same axis... :(

Touch Pad Settins Touch Pad Settins

Keyboard Orbit Settings (orbit camera) Keyboard Orbit Settings

When KeyboardOrbit is set to Horizontal and Vertical or Mouse X and Y, it works well on pc keyboard/mouse, but on phone don't. I also created ZoomAxis but it also don't work with this script (in this case only Fire1 Fire2 axis works).

In orginal KeyboardOrbit script I added/changed:

 public string horizontalAxisName = "Horizontal";
 public string verticalAxisName = "Vertical";
 public string zoomAxisName = "ZoomAxis";
 
 x -= Input.GetAxis(horizontalAxisName) * xSpeed * 0.02f;
 y += Input.GetAxis(verticalAxisName) * ySpeed * 0.02f;
 
 distance -= Input.GetAxis(zoomAxisName) *zoomSpeed* 0.02f;
 distance += Input.GetAxis(zoomAxisName) *zoomSpeed* 0.02f;

ZoomAxis settings:

 Name ZoomAxis
 Negative Button -
 PositiveButton +
 Gravity 1000
 Dead 0.001
 Sensitivity 1000
 Snap off
 Invert off
 Type Key or MouseButton
 Axis X axis
 Joy Num Get Motion from all Joystics

capture1.jpg (20.6 kB)
capture2.jpg (27.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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by shruikan · Sep 10, 2015 at 06:25 PM

I found the solution. I had to add/change some lines to the KeyboardOrbit script that read touch imput.

 using UnityEngine;
 using System.Collections;
 
 public class CameraMoveTouchscreen : MonoBehaviour {
     
     public Transform target;
     public float distance= 1.5f;
     public float xSpeed= 175.0f;
     public float ySpeed= 75.0f;
     public float pinchSpeed = 0.5f;
     
     private float lastDist = 0;
     private float curDist = 0;
     
     public int yMinLimit= 10; 
     public int yMaxLimit= 80;
         
     public float minDistance= 0.5f;     
     public float maxDistance= 1.5f;
         
     private float x= 0.0f;
     private float y= 0.0f;
     
     private Touch touch;
     
     
     void  Start () {
         Vector3 angles= transform.eulerAngles;
         x = angles.y;
         y = angles.x;
 
         // Make the rigid body not change rotation
         if (GetComponent<Rigidbody>())
             GetComponent<Rigidbody>().freezeRotation = true;    
     }
     
 
     void  LateUpdate (){
         if (target && GetComponent<Camera>()) {
 
             if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved) {
                 
                 touch = Input.GetTouch(0);
                 x += touch.deltaPosition.x * xSpeed * 0.02f;
                 y -= touch.deltaPosition.y * ySpeed * 0.02f;
                 y = ClampAngle(y, yMinLimit, yMaxLimit);
             }
 
             if (Input.touchCount == 2 && (Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(1).phase == TouchPhase.Moved)) {
 
                 Touch touchZero = Input.GetTouch(0);
                 Touch touchOne = Input.GetTouch(1);
 
                 Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
                 Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;
 
                 float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
                 float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;
 
                 float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;
 
                 distance += deltaMagnitudeDiff * pinchSpeed * 0.02f;
                 distance = ClampAngle(distance, minDistance, maxDistance);
 
         }
             Quaternion rotation= Quaternion.Euler(y, x, 0.0f);    
             Vector3 vTemp = new Vector3(0.0f, 0.0f, -distance);
             Vector3 position = rotation * vTemp + target.position;
             
             transform.rotation = rotation;
             transform.position = position;    
         }
     }
     
 
     static float ClampAngle (float angle, float min, float max) {
         if (angle < -360)
             angle += 360;
         if (angle > 360)
             angle -= 360;
         return Mathf.Clamp (angle, min, max);    
     }
 }

 
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 DawdleDev · Dec 19, 2017 at 06:32 PM 0
Share

@shruikan What is this touchpad for? Can it be used for the touchpad on DualShock4 remotes?

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Make object follow my finger (Touch)? 1 Answer

switch keyboard controls to simple tap controls,Android touch controls for simple mobile game testing 0 Answers

Make touch buttons stop working after finger slides off. 1 Answer

check touch position 2 Answers

How to make a true virtual keyboard for computer in Unity? 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