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
0
Question by Noah-1 · Dec 29, 2011 at 06:07 PM · mouserotatetargetorbitaround

Move camera around object IOS

Hello guys! well I have been trying to figure this out for quite some time but for some reason I can´t get it working...

This is the thing I have already a mouse Orbit Script from someone at Unity Forums (can´t remember who) it works perfectly! and I want to do the same one for the iphone but it must work with finger swipes (I already added some code to detect them). Can you guys help me with the RotateAround part?

Any ideas?

Here is the mouse Orbit code, it is pretty simple:

 var target : Transform;
 var distance = 10.0;
 var cameraSpeed = 5;
 
 var xSpeed = 175.0;
 var ySpeed = 75.0;
 
 var yMinLimit = 30; //Lowest vertical angle in respect with the target.
 var yMaxLimit = 80;
 
 var minDistance = 5; //Min distance of the camera from the target
 var maxDistance = 20;
 
 private var x = 0.0;
 private var y = 0.0;
 
 
 
 
 function Start () {
     var angles = transform.eulerAngles;
     x = angles.y;
     y = angles.x;
 
    // Make the rigid body not change rotation
       if (rigidbody)
       rigidbody.freezeRotation = true;
 }
 
 function LateUpdate () {
     if (target && camera) {
 
    //Zooming with mouse
    distance += Input.GetAxis("Mouse ScrollWheel")*distance;
    distance = Mathf.Clamp(distance, minDistance, maxDistance);
 
    //Detect mouse drag--> PC input;
    if(Input.GetMouseButton(0))   {
    
         x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
         y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;  
              
       }//Left
       
       y = ClampAngle(y, yMinLimit, yMaxLimit);
               
         var rotation = Quaternion.Euler(y, x, 0);
         var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
          
    transform.position = Vector3.Lerp (transform.position, position, cameraSpeed*Time.deltaTime);
       transform.rotation = rotation;      
     }
     
     //Detect swipes--> iPhone Input
 
     
     for (var evt: iPhoneTouch in iPhoneInput.touches){
     
     if(evt.phase == iPhoneTouchPhase.Moved ){
 
 
     //Here is where I need to do the exact same thing that was done with the mouse;
  
     
     }
     }
     
     
     
 }
 
 static function ClampAngle (angle : float, min : float, max : float) {
    if (angle < -360)
       angle += 360;
    if (angle > 360)
       angle -= 360;
    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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by GameFreak · Dec 29, 2011 at 08:44 PM

I can write down the code for you if you say.

But I would rather suggest just import the Standard Assets (Mobile) and use the prefabs / scripts to do your job.

If youre using scripts tell me I will tell you how to make the joystick and use it.

--Rishab

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 Noah-1 · Dec 29, 2011 at 08:53 PM 0
Share

I can use the Standard Assets ($$anonymous$$obile) but that´s not what I am looking for. I want something like the right joystick but with finger Swipes.

avatar image GameFreak · Dec 30, 2011 at 07:14 PM 0
Share

Finger swipes? Use for (var touch : iPhoneTouch in iPhoneInput.touches) { if (touch.phase == iPhoneTouchPhase.$$anonymous$$oved)

 {
    var FingerDid$$anonymous$$ove=true;
 }    
 }

If you want to drag an object google it :)

avatar image GameFreak · Dec 30, 2011 at 07:14 PM 0
Share

Finger swipes? Use for (var touch : iPhoneTouch in iPhoneInput.touches) { if (touch.phase == iPhoneTouchPhase.$$anonymous$$oved)

 {
    var FingerDid$$anonymous$$ove=true;
 }    
 }

If you want to drag an object google it :)

avatar image
0

Answer by BalsamicVinegar · Feb 01, 2012 at 07:03 AM

More of a head start than an aswer, but this should work for your swipe detection and your Y axis rotation. X axis is a little more complex and I'm a bit too busy at the moment to figure it out. But I'm sure the mouse orbit script has a good solution.

 Vector2 orbit = Vector2.zero;
 
     if(Input.touches.Length > 0) {
     
         //Just grab the first touch
         if(Input.touches[0].phase == TouchPhase.Moved) {
         
             //If it's moving, grab the amount of movement
             orbit = Input.touches[0].deltaPosition;
         }
         
     }
     
     if( orbit != Vector2.zero) {
     
         //Ok, so if there is movment then we rotate the camera around the player
         
         //I'm going to assume you have four variables here.
         //1. the target transform  - I'll call this _target
         //2. The distance the camera is from the target - I'll call this _distance
         //3. A Vector2 with the current amount of rotation you have given the camera - I'll call this _currentRotation
         //4. A reference to the camera object - I'll call this _camera ..... IF this is attached to the camera object, just use gameObject.transform instead
         
         //First move the camera to the target
         _camera.position = _target.position + (_target.forward * _distance);
         
         //Now add the movement onto the _currentRotation variable
         _currentRotation.x += orbit.x * Time.deltaTime;
         _currentRotation.y += orbit.y * Time.deltaTime;
         
         //This works fine for rotation around the y axis.
         _camera.RotateAround(_target.up, _currentRotation.x);
         
         //Now to rotate on X it is quite awkward. Just using the _target.right will cause issuses when you rotate on y
         //You will probably need to split the 360 degree rotation into 90 degree quadrants and figure out which axis is appropriate
     
     }
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

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Look Behind Me While Still Moving Forward 1 Answer

Making an object rotate around a sphere 1 Answer

Camera orbit around clicked position 0 Answers

unity2D: make object face mouse 2 Answers

Trouble with moving the camera. 2 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