Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Rotation of the game object by the player

Discussion in 'Unity UI & TextMesh Pro' started by yuspacex, Aug 12, 2018.

  1. yuspacex

    yuspacex

    Joined:
    Jun 10, 2018
    Posts:
    1
    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...

    0481f40f-adaf-4240-ae08-36924f3c1f3c.png
     
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    570
    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)
    Update:
    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
    yuspacex likes this.