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
1
Question by superlol · Mar 20, 2011 at 01:01 PM · cameraorbit

camera orbit like star defence

Hi folks!

How Can I do a mouse orbit like this?

http://www.youtube.com/watch?v=OouBzirUZww&feature=related

The mouse orbit in the standard assets is limited :|, when I'm at the top of the sphere the camera spins!

Tnx a lot :)

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
2
Best Answer

Answer by Keeblebrox · Mar 20, 2011 at 02:26 PM

Yeah, I could understand you'd have issues using mouse orbit. I suggest you combine Transform.LookAt( Vector3 ), to keep the camera looking at your target, with regular movement scripting.

In untested C#

using UnityEngine; using System.Collections;

public class FreeformMouseOrbit : MonoBehaviour { public Transform target; public float desiredDistance = 10.0f;

 // should be used for all camera-movement scripts
 public void LateUpdate()
 {
     // focus camera on target
     transform.LookAt( target.position );

     // ... use science to figure out direction of travel relative to camera (up, right, down, left, or a combination)
     Vector3 movementVector = science;

     // move in that direction
     transform.position += movementVector;

     // if you have problems with zoom, move the camera so that it's the appropriate distance from the target
     float actualDistance = Vector3.Distance( transform.position, target.position );
     if( !Mathf.Approximately( desiredDistance, actualDistance ) )
     {
         Vector3.MoveTowards( transform.position, target.position, Mathf.Abs( actualDistance - desiredDistance ) );
     }
 }

}

Now in untested JS:

// FreeformMouseOrbit.js public var target : Transform; public var desiredDistance : float = 10.0;

// should be used for all camera-movement scripts public function LateUpdate() : void { // focus camera on target transform.LookAt( target.position );

 // ... use science to figure out direction of travel relative to camera (up, right, down, left, or a combination)
 var movementVector : Vector3 = science;

 // move in that direction
 transform.position += movementVector;

 // if you have problems with zoom, move the camera so that it's the appropriate distance from the target
 var actualDistance : float = Vector3.Distance( transform.position, target.position );
 if( !Mathf.Approximately( desiredDistance, actualDistance ) )
 {
     Vector3.MoveTowards( transform.position, target.position, Mathf.Abs( actualDistance - desiredDistance ) );
 }

}

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 superlol · Mar 21, 2011 at 11:22 AM 0
Share

Hi tnx for the reply :)

Science it's a mistery for me and I code only in js so I can't go throw this :)...

avatar image Keeblebrox · Mar 23, 2011 at 04:03 AM 0
Share

I added a JS version of the code if that helps. As for science, I left that part vague as it's up to your control scheme.

One possible method, if you're developing with the iPhone in $$anonymous$$d, would be to subtract the current touch point from the previous touch point and use the resulting vector (science = previousTouchPoint - currentTouchPoint). I'm not familiar enough with the iPhone API to give you code for that, though. I suggest going over the info at http://unity3d.com/support/documentation/ScriptReference/Touch.html

avatar image JustinTheSwift · Feb 09, 2017 at 12:59 AM 0
Share

science is undefined, making this answer unhelpful.

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

1 Person is following this question.

avatar image

Related Questions

Enable the OrbitCam script how can I make it will continue from the current camera view and position ? 0 Answers

Gyroscope Orbit Android 1 Answer

Mouse/Wacom stylus drag not working. 1 Answer

Rotate camera outside of movement lerp? 0 Answers

orbit mouse camera animation movement script 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