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 /
  • Help Room /
avatar image
0
Question by manuel2258 · Jul 02, 2016 at 06:53 PM · androidunity 5movementtouchjoystick

Player i spining when moving

I currently want to make a game for android, where you can move the player over an virtual joystick and if you press on the screen the player looks at the mouse. But i got the problem that if it looks at the mouse and then move it will just randomly spin. It's not caused of two touch inputs at the same time, because i had the same issue when i used my keyboard with W,A,S,D. For the Joystick i use the Standart Unity 2D Input. Thats the Script of the player:

 // Update is called once per frame
     void Update () {
         //Movement 
         var mousepos_screen = Input.mousePosition; //Gets the Screen Cordinates of the mouse in pixels
              
         var in_x = CrossPlatformInputManager.GetAxis("Horizontal"); //Returns 1;-1 if in this frame a key was pressed, thats in the "Horizontal" group
         var in_y = CrossPlatformInputManager.GetAxis("Vertical"); //Returns 1;-1 if in this frame a key was pressed, thats in the "Vertical" group
         myrigid.velocity = new Vector2(in_x, in_y) * speed * Time.deltaTime; //Sets the velocity of this Object to the Input; Gets multiplied by movementspeed and gamespeed
 
 
         //Rotation
 
         if (Input.GetMouseButton(0) && (mousepos_screen.x > 200 || mousepos_screen.y > 200))
         {
             //Debug.Log("MouseDown == true");
             mousepos_screen.z = Camera.main.transform.position.z; //Sets the z component to the height of the player
             var mousepos_world = Camera.main.ScreenToWorldPoint(mousepos_screen); //Translate the Screen Condinates to World Condinates
             var dif = mousepos_world - transform.position; //Gets the Vector; (Spitze - Fuß)
             var angle_rad = Mathf.Atan2(dif.y, dif.x); //Gets the Tangens in Radians
             var angle_deg = Mathf.Rad2Deg * angle_rad; //Translate the Radians to Degrees
             transform.rotation = Quaternion.Euler(0, 0, angle_deg - 269); //Rotate the Object  
             //Debug.Log("World: " + mousepos_world);
         }
         //Debug.Log("Screen: " + mousepos_screen);
     }

I could also make a video of it and upload it to Youtube if you want. If anybody knows whats wrong with my script pls tell me! Thank you, Manuel Schmidbauer

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

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

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

Pinch to zoom camera: trembling when at minimum zoom 0 Answers

My character carries on the run animation for a few seconds even after standing still 0 Answers

Movement with joystick ,Moving object with the Joystck 0 Answers

Error : The second touch should not work at all. How do I fix this error?,Error: The second touch should not work at all. How do I fix this error? 0 Answers

Multitouch on Android: position incorrect 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