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 boaretas · Feb 14, 2017 at 05:52 AM · cameracamera-movementtileisometricperspective

Isometric Prespective camera drag/drop

The main camera of my game is set up as a perspective camera with rotation x:36,y:-34,z:0. It gives me a pretty nice "isometric" view of the game. This looks like this:alt text

I want to make the camera "draggable". Not like in a RTS that the camera moves when the mous is getting out of the fiel of view, more kind of a camera drag in thouse mobile building games. I set up all of this woth an ortographic camera, which is no problem, but I'm really struggling with the perspective camera view. To move the camera I gave the ground (this visible grid) a box collider to measure the distance from mousbuttondown to the drag mposition of the mouse. It works good like this but it is insanely fast and not at all accurate. Furtheermore it drags forever and does not stop when it reaches the desired destination. My code currently looks like this:

     Vector3 startpos;
 
     void OnMouseDown() {
 
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         Plane plane = new Plane(Vector3.up, Vector3.zero); 
         float distance = 0f;
         Vector3 point = ray.GetPoint(distance);
         startpos = point;
 
     }
 
 
     void OnMouseDrag()
     {
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
 
         Plane plane = new Plane(Vector3.up, Vector3.zero); 
         float distance = 0f;
 
         Vector3 point = ray.GetPoint(distance);
 
         Vector3 diff = startpos - point;
 
         Camera.main.transform.position = Camera.main.transform.position - diff;
 
       
     }

I tried to update the start position when finish moving like this:

         Camera.main.transform.position = Camera.main.transform.position - diff;
 

But it will just zoom in forever... Can anyone giving me an advice what I am doing wrong or how to do this?

iso.png (119.5 kB)
Comment
Add comment · Show 1
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 boaretas · Feb 13, 2017 at 02:05 PM 0
Share

I made another attempty but I'm not sure if this is a clean way... I created a enmpty gameobject called "CA$$anonymous$$ERA" and added the camera as a child to it. So the "CA$$anonymous$$ERA" has no rotation at all only the real camera child. Using this you can simply calculate the screenpointtoray difference from the mousedown event to the drag event pointtoray... But this looks like a really quick and dirty way to me...

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Isometric - Camera follow an object when at the edge of the screen 1 Answer

How to make a 3D camera rotate relative to the world? 1 Answer

Forward and back movements with a camera emulating an isometric view 1 Answer

Camera movement and gun follow in unity 1 Answer

Camera follow a sphere which look at another object on the ground 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