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

Transform.position how to ignore rotation?

Discussion in 'Scripting' started by d3x7er, May 10, 2021.

  1. d3x7er

    d3x7er

    Joined:
    Jun 23, 2018
    Posts:
    40
    I have an issue when trying to rotate an object with transform.RotateAround and after that i want to change it's position with transform.position.

    So here is an example if i have object with:
    rotation: x = 0, y = 0, z = 0 and set:
    transform.position = new Vector3(1,1,1);

    it will work as expected. So how can I get the same result when i have my object rotated like:
    rotation: x=0, y=90,z=0
    transform.position = new Vector3(1,1,1) -> how can I make this position change work?
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    You have to be more precise about what your end goal is. What you have stated here will work in that the world position of the object will end up at (1, 1, 1). But if you want something different than that, perhaps you want to move the object 1, 1, 1 in its own local coordinate system after the rotation you need to express that.

    Basically - be more precise about what you're looking for.
     
    Joe-Censored likes this.
  3. d3x7er

    d3x7er

    Joined:
    Jun 23, 2018
    Posts:
    40
    Yes exactly I want to move it in local position after rotaitng. More precisely i have a camera that I am rotating with "RotaetAround". And after that I would like to move the camera to a specific position.