Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

RotateAround an object with using Quaternion

Discussion in 'Scripting' started by sayginkarahan, Jun 2, 2021.

  1. sayginkarahan

    sayginkarahan

    Joined:
    Jan 23, 2015
    Posts:
    49
    Hi everyone,

    I have a great question for code masters. Think about you have only a calculated rotation value to rotate the transform. But you have to rotate around with its child pivot position. How do you solve this problem?

    Thank you for your time :)

    QAV5.png
     
    Last edited: Jun 2, 2021
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,749
    AcidArrow likes this.
  3. sayginkarahan

    sayginkarahan

    Joined:
    Jan 23, 2015
    Posts:
    49
    Thank you for your quick reply but I'm not good at reading math formulas. That's why I couldn't understand most of the post you shared. I need a solution in C# :)

    But, I think I understand what you mean. I'll give it a try, Thanks.
     
    Last edited: Jun 2, 2021
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,749
    Me neither. Steps to success:

    1. subtract the offset amount (vector)
    2. do the rotation by the quaternion
    3. add the offset amount back (vector)

    You can do it!
     
    sayginkarahan likes this.
  5. sayginkarahan

    sayginkarahan

    Joined:
    Jan 23, 2015
    Posts:
    49
    Thank you, I can do it :) You're amazing, really ;)
     
    Kurt-Dekker likes this.
  6. sayginkarahan

    sayginkarahan

    Joined:
    Jan 23, 2015
    Posts:
    49
    Hello everyone,

    Thanks to Kurt-Dekker suggestion, I wrote the code.
    Here is the solution.

    Solution.png