Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 dcrzce · May 24 at 11:57 PM · debug

Mouse drag bad rotation

Hey, so I have this script set up to rotate my cam pivot when i drag the screen with the mouse and encontered an issue i wasn't able to fix, my cam rotates on the z axis and completely ruins everything xD I wondered if someone could help me getting this script working fine and maybe upgrade it a bit ( i know it is kind of a rude method of changing rotation xD ) Anyways, thanks for reading

  void Update()
  {
  transform.position = player.transform.position;

  if (Input.GetMouseButtonDown(0)) {
  PressPoint = Input.mousePosition;
  StartRotation = transform.rotation;
  }
  else if (Input.GetMouseButton(0)) {
  Vector3 CurrentDistanceBetweenMousePositions = new Vector3(-(Input.mousePosition - PressPoint ).y,      -(Input.mousePosition - PressPoint ).x, 0);
  transform.rotation = StartRotation * Quaternion.Euler( CurrentDistanceBetweenMousePositions / 
  SceneWidth * 360);
  }
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

Answer by zORg_alex · May 25 at 07:38 AM

You should play with multipliers.

 public float RotationMultiplier = 360;//As you have now
 ...
 transform.rotation = StartRotation * Quaternion.Euler( CurrentDistanceBetweenMousePositions / 

SceneWidth * RotationMultiplier );

Play with that parameter to find out what is the best for you.

The script itself is kind of wonky, but it should do.

I've personally stopped using legacy Input class, I switched to a new InputActions. But you need to dig it. First you need to install that package InputActions, second you'd need to switch project settings to use both piplines, since you probably have a ton of legacy Input, so it will be a pain to do at once, plus all scripts you get from internet and assets are probably still are using only legacy Input. Then create either an asset with all inputs you'd listen to or create them dynamically in code or in editor for every script. It seems like a hassle, but using legacy Input for multiple players/gampads/mice/keyboards... Is even more hassle. So for prototypes I use a code creation of InputActions.

Comment
Add comment · 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

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

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

Related Questions

Having some problems with randomization 2 Answers

Problem with android on screen GUI 1 Answer

Which Gizmo is Debug.DrawLine? 1 Answer

How to find 'unreleased' references programmatically and prevent not enough memory crashes? 0 Answers

Double clicking console output does not take me to the corresponding line in code. 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