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 sagicoh · Nov 12, 2021 at 12:48 PM · mouse-dragrotaion

Move 3d objects in axis according to camera

I have a 3d object(cube) and I want to move it in a single axis according to both mouse-drag (which translates to up/down/left/right) and camera rotation around that cube. (to rotate the camera around the object I followed https://github.com/EmmaPrats/Camera-Rotation-Tutorial).

For example if the camera rotation is (0,0,0) and the swipe direction is up the direction Vector3 I get should be (0, 1, 0). If the camera rotation is (90,0,0) and the swipe direction is up the direction Vector3 I get should be (0, 0, 1).

You can disregard camera rotation in the Z-axis. As I dont rotate the camera around it.

How can I achieve that?

Thanks

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 Kona · Nov 12, 2021 at 01:23 PM

There's a handy method of the Tranform class to use for this purpose.

https://docs.unity3d.com/ScriptReference/Transform.TransformDirection.html

To get a direction relative to a game object's transform component:

 Vector3 inputDir = new Vector3( Input.GetAxis( "MouseX" ), Input.GetAxis( "MouseY" ), 0f );   //Get mouse motion, I think it's called MouseX and MouseY, check the input settings though.
 Vector3 camToWorldDir = Camera.main.transform.TransformDirection( inputDir );  //Creates a new vector pointing in the inputDir relative to the main camera's current 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 sagicoh · Nov 12, 2021 at 01:53 PM 0
Share

thanks, ill try that. will it work in mobile as well? (seeing as it's name is mouse..)

avatar image Pangamini sagicoh · Nov 12, 2021 at 02:01 PM 1
Share

The first line with the mouse part is the input method. The conversion happens in next lines. Obviously, you can change your input method to whatever you want

avatar image sagicoh Pangamini · Nov 12, 2021 at 02:21 PM 1
Share

Yea I checked about it. I though it was some complicated math or something.. I think it works now :) thanks a lot!

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

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

Related Questions

Trajectory on mouse up 0 Answers

How to deal with collision by using mouse drag? 0 Answers

How to move object with mouse at same rate of mouse - 2D 1 Answer

Move Camera once Mouse Drag is complete 2 Answers

Determine 2d direction between mouse click and release. 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