Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Rotation of the game object by the player

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

  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
    yuspacex likes this.