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 Seeane · Feb 15, 2014 at 02:54 PM · camerapositionorthographicaimperspective

Orthographic position to Perspective position

Hi everyone,

The question might be a little bit tricky, but I hope someone can help me.

I have a GUI button, rendered by a GUI camera, which is set on orthographic view. I have another camera, the main camera, which is set on perspective view.

When I dragg my GUI button, it gives my character a position to aim. When I release the dragg, an arrow is instantiated in direction of the GUI button direction.

But, as you can see in the screenshot below, the orthographic position and the perspective position are not the same at all, resulting on an approximative aiming.

alt text

So, is there anyway to make both position coincide?

A little bit of my code, regarding to the "dragging" and instantiate part :

  void OnMouseDrag()
     {
         Vector3 currentScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, aimTarget.z);
         Vector3 currentPosition = guiCamera.camera.ScreenToWorldPoint(currentScreenPoint) + offset;
         transform.position = currentPosition;
         if (startMousePosition != Input.mousePosition)
         {
             aimController.GetComponent<AimController>().enabled = true;
             if (transform.localPosition.x < 0)
             {
                 playerController.moveDirAccess = -1;
             }
             if (transform.localPosition.x > 0)
             {
                 playerController.moveDirAccess = 1;
             }
         }
         else
         {
             aimController.GetComponent<AimController>().enabled = false;
         }
     }

  void OnMouseUp()
     {
         GameObject.Find("AimButton").transform.localPosition = startlocalPosition;
         aimController.GetComponent<AimController>().enabled = false;
         newArrow = (GameObject)Instantiate(Resources.Load("Arrow"), arrowPosition.transform.position, arrowPosition.transform.rotation);
         newArrow.rigidbody.velocity = arrowPosition.transform.TransformDirection(arrowForce, 0, 0);
         playerController.audio.PlayOneShot(playerController.arrowSound);
         newArrow.name = "Arrow";
         Physics.IgnoreCollision(newArrow.collider, collider);
         if (playerCharacter.transform.rotation == faceLeft)
         {
             arrowPosition.transform.rotation = new Quaternion(0.0f, 1.0f, 0.0f, 0.0f);
         }
         else if (playerCharacter.transform.rotation == faceRight)
         {
             arrowPosition.transform.rotation = new Quaternion(0.0f, 0.0f, 0.0f, -1.0f);
         }
         playerController.speed = 12;
         playerController.jumpHeight = 16;
         backgroundAimButton.SetColor("_Color", new Color(1, 1, 1));
         playerController.animator.SetBool("Bending", false);
     }




unityorthopersp.png (73.8 kB)
Comment
Add comment · Show 2
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 robertbu · Feb 15, 2014 at 03:42 PM 0
Share

What you can do is to get either the viewport or screen coordinate of the button using the GUI camera. Then use that coordinate and the perspective camera to get the world coordinate to aim at.

avatar image Seeane · Feb 16, 2014 at 07:26 PM 0
Share

Hi robertbu,

Thank you so much for your help. I managed to make it work by following your advice!

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

18 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 avatar image avatar image avatar image avatar image

Related Questions

Calculate approximate or same size and position of an 2d sprite(plane) object so it appears the same rendered with orthographic and perspective camera 0 Answers

How can I keep three targets in sight, and keep the camera above a specific height - while it resizes? 0 Answers

Using a perspective camera can an object act as if viewed by orthographic camera? 1 Answer

Camera 2D RPG in perspective 1 Answer

Draw orthographic visuals (e.g. health bar) in perspective scene? 4 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