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

Question How to change orientation having from x1,y1,z1 to xn,yn,zn corrdinates data saved in database

Discussion in 'Scripting' started by RCodelove, Aug 21, 2023.

  1. RCodelove

    RCodelove

    Joined:
    Aug 9, 2023
    Posts:
    22
    I want to rotate in an arc shap with a given set of from x,y,z values to x,y,z values,

    Example if x1=-40, y=2, z3 to xn=45, y=3, z3
    it's almost 85 degree.

    How to do that?
     
  2. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,108
    85 deg between two points on space? How, what does it mean?
     
  3. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,630
    Use Quaternion.LookRotation to get two quaternions, one pointing at the first point and another pointed to the second point. Then Quaternion.Slerp to smoothly interpolate from the first quaternion to the second one.

    This assumes your points are centered around 0,0,0 and that you only care about rotation.
     
  4. AngryProgrammer

    AngryProgrammer

    Joined:
    Jun 4, 2019
    Posts:
    431
    Quite hard to decode the description. We have in transform 3 sets of vectors: position, rotation, and scale. So like logic goes, with the position we set x, y, z of the game object in space, and with the rotation we set angles in x, y, z space.
     
    Bunny83 likes this.
  5. RCodelove

    RCodelove

    Joined:
    Aug 9, 2023
    Posts:
    22
    You can look into this video, bat initial position is -6 or -8 on the x axis, and bat then reached around -35 on x axis and then it move forward and it reached +40 in x axis, how this can be done programmatically.
    Basically we will save all the matrices data from sensor and then load it from database and then model will change accordingly.
    Right now can choose some static data to start and later will load it from remote.
    How to do that?
     

    Attached Files:

  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    Rotation, not Position. You mentioned in a previous post that you were an experienced dev so you'll know that these words are important.

    Move forward? It's rotating, not moving in position/translation.

    Do what? How to rotate? Have you looked at the Transform component?
     
    wideeyenow_unity and Bunny83 like this.
  7. AngryProgrammer

    AngryProgrammer

    Joined:
    Jun 4, 2019
    Posts:
    431
    You can create a simulation loop that iterates through time steps. In each iteration, update the position/rotation of the bat based on the sensor data. The final solution you put inside the Update method of a script attached to the bat.

    But if it's one shoot sensor load you want to use for animation, I think it is better to use the Animator component.
     
  8. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,630
    That's not the position, that's the rotation.

    The gif just shows an object being rotated, nothing more. If that's what you need, transform.Rotate.