• 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 Apsiya · Dec 21, 2017 at 02:48 PM · unity 5gameobjectrigidbody2dtouch controls

I want to rotate the 2D missile with touch controls

Hi i'm making a game and i spent days to resolve my problem but i didn't succeeded my problem is i want to control a missile with touch i will explain , first i will touch anwhere on the screen and if i rotate my finger to the left the gameobject must rotate left and vice versa , the game object have a rigidbody2D can anyone help me please

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 royhammel · Dec 22, 2017 at 02:20 AM

I can't imagine how you'd do this with either capacitive or resistive touch screens. you would need a second finger to track or you would need to track the angle the finger was dragged out instead of keeping it in one place. this is because current touch screen technology only tracks the touch location and not the orientation of the finger. another possibility is the use of custom hardware to track the rotation, but that would be a pretty hard road to go down.

to do the two-finger solution, track either the angle or angle change (depending on how you want it to act) between the fingers and use that for rotation. for the dragging solution, track the first touch location and use the current location as well as the location where you let your finger up as the second location for tracking the angle. arctangent is your goto trig function here.

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 Apsiya · Dec 22, 2017 at 09:39 AM 0
Share

hey royhammel , Thank you for your response i really appreciate your help , i think i didn't explain my problem very well all i want is when i drag my finger on the screen on a rotation mouvement (not rotate my finger) the gameobject will rotate also (like the game GoPlane on playstore) could you help mye with this please ?

avatar image royhammel Apsiya · Dec 22, 2017 at 02:12 PM 0
Share

yes. I can help you with it. it's actually pretty simple. what you want is the change in the angle from one frame to the next of the rotation of your finger's position around the game object. this change in angle is what you apply to the game object.

you get this by feeding the vector resulting from the position of the game object subtracted from the position of your finger on the screen. there is a very convenient function for doing this called atan2(). it's a special implementation of arctangent that takes a delta x and a delta y and returns an angle. always keep track of the previous angle while the user's finger is still on the screen. the difference between that angle and the current angle is the actual change you apply to the game object's rotation.

avatar image royhammel Apsiya · Dec 27, 2017 at 04:50 PM 0
Share

did that help?

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

Animation won't stop (Solved) 2 Answers

How attach C# script by argument? 3 Answers

Rigidbody2D to go through Box Collider 2D 1 Answer

Grenade damage script error 0 Answers

Many objects with decimal place in the millionths, can this cause any performance issues? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges