Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Rotation of the game object by the player

Discussion in 'Unity UI & TextMesh Pro' started by yuspacex, Aug 12, 2018 at 7:05 AM.

  1. yuspacex


    Jun 10, 2018
    Hello guys...
    I want the game object to be rotated by the player like in image.
    How can I do that? any tutorials or sites do you know?
    Thanks for answer...

  2. Hosnkobf


    Aug 23, 2016
    You are in the wrong forum (this belongs more to scripting I would say).
    I try to answer you anyways (but not with script, so you are still challenged a bit ;))

    Preparation (When "Double-Drag" starts):
    1. Find the position in the middle of both fingers (okay, I provide you a bit of math: (fingerA + fingerB) / 2)
    2. convert that position into the local coordinates of the bar (this is the pivot of your transformation - if the object also has a pivot itself, subtract that one from the result)
    3. store the current rotation of the object
    4. store the angle between both fingers (you can use Mathf.Atan2(y, x) for it)
    1. find the position in the middle of both fingers (see above)
    2. set the global position of the bar to the calculated position plus the calculated pivot
    3. find the angle between both fingers (like in Perparation 4.)
    4. Set the rotation to the calculated angle minus the results of Preparation 3. and 4.
    Edit: I did a little mistake at Update 2:
    that should be done as the last step. and the pivot has to be transformed using the current angle (using sine and cosine).
    Last edited: Aug 13, 2018 at 4:24 PM
    yuspacex likes this.