Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    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. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Don't miss out on the Unite LA Keynote for the latest information from Unity! Set a reminder!
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  6. 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.

  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:
    397
    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.