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 Flemingjp · Jun 19, 2013 at 07:44 PM · cameravector3mousetranslaterts

Translate Point By Vector3 And Angle

I am writing a camera script for a RTS game. Currently it can orbit and zoom around a point. The target point. I want the player to be able to 'pan' around by moving the mouse onscreen. The mouse movements on screen will then be used to translate this target point.

Currently I can get the vector from the users screen from where the first click (the new origin).

 if(Input.GetMouseButtonDown(0)) {
     dragOrigin = Input.mousePosition;
 }
 
 Vector3 pos = Camera.main.ScreenToViewportPoint(Input.mousePosition - dragOrigin);
 Vector3 move = new Vector3(-pos.x * 2.0F, 0, -pos.y * 2.0F);

How can I translate the current point

 Vector3 target = (0.0F, 0.0F, 0.0F);


Taking into account the rotation my camera is angled at, say 30 degrees. This is only for the X and Z coords. The Y is always 0.0F in this context.

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 FlaSh-G · Jun 19, 2013 at 08:30 PM

If you make your target point the rotated object, you can use Transform.TransformDirection to move it relatively to its rotation.

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 Flemingjp · Jun 20, 2013 at 05:08 PM 0
Share

The target point isn't a transform. Just a Vector3. Im wating to take the vector3 and translate it by a vector created from how the user has dragged their mouse. $$anonymous$$G - $$anonymous$$y target pos = (30.2F, 0.0F, 15.0F) mousemove pos = (1.5F, 0.0F, 2.5F); camera is 30 deg on XZ plane new target pos = (X, Y, Z);

avatar image FlaSh-G · Jun 20, 2013 at 05:41 PM 0
Share

$$anonymous$$ake it a transform then, it saves you a lot of work and you'll get much cleaner code.

avatar image Flemingjp · Jun 20, 2013 at 06:41 PM 0
Share

Thanks a lot :-) took a bit of fiddling but it works perfectly now

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

15 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

Related Questions

How to get the forward vector normal to the camera's forward vector regardless of camera pitch 1 Answer

Orbital cameras and dragging objects with mouse. 0 Answers

Move Camera According to Mouse Movement While Button is Pressed 1 Answer

How to setup camera look at mouse on right click 0 Answers

Detect Mouse in right side or left side For Player? 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