Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Object.transform.position is not working in hdrp

Discussion in 'Scripting' started by Perryhan, Aug 23, 2019.

  1. Perryhan

    Perryhan

    Joined:
    Oct 31, 2018
    Posts:
    6
    Hi! I am newbie in Unity, and I am trying to use object.transform.position, but it made object moving randomly.

    public GameObject Light;
    public GameObject Scenesetting01;
    public GameObject Scenesetting02;
    public GameObject Player;
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

    }

    public void Morning()
    {
    Scenesetting01.SetActive(true);
    Scenesetting02.SetActive(false);
    Light.SetActive(false);
    }

    public void Night()
    {
    Scenesetting01.SetActive(false);
    Scenesetting02.SetActive(true);
    Light.SetActive(true);
    }

    public void MoveToInterior()
    {
    Player.transform.position = new Vector3(-39, 10, 10);
    Player.transform.rotation = Quaternion.Euler(0, 180, 0);
    }

    Here's what I used for transform.position and rotaiton.

    After I applied this, the player moved to the point where I did not set.

    Please help me.

    Thank you!
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    6,669
    First, use [code ]code tags [/code].

    Second, as far as I can tell that code wouldn't move anything at all. Your MoveToInterior function (and all your other functions) aren't being called anywhere, unless they're being linked from somewhere else (like a UI button).

    Do you have any errors in the console? Are there other scripts that might be moving the object? What position is the object actually being moved to? (A screenshot would be ideal for the last one as that can reveal other issues as well)
     
  3. Perryhan

    Perryhan

    Joined:
    Oct 31, 2018
    Posts:
    6
    Thank you so much for your reply!

    캡처.PNG
    My character is supposed to move to the red way, but when I clicked the button in blue spot, it made me moving toward black way.

    If you do not mind, could you provide me some examples of transform :(?

    Thank you!
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    6,669
    A screenshot of the editor window (including the Inspector and Hierarchy windows, with the moved object selected) would be more helpful in figuring out the problem.
     
  5. Perryhan

    Perryhan

    Joined:
    Oct 31, 2018
    Posts:
    6
    제목 없음.png
    This is a snap before I clicked the button with the script that I attached.

    제목 없음1.png This is a snap when I clicked the button. I was supposed to move opposite way.

    Thank you!
     
  6. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    6,669
    Is the object you're moving a child of something else? If so, then "transform.position" (which refers to the world space position) won't look the same as what you see in the inspector. Maybe try transform.localPosition instead?
     
  7. Perryhan

    Perryhan

    Joined:
    Oct 31, 2018
    Posts:
    6
    Hi! Thank you for replying, I reply back too late due to time difference.

    What do you mean localposition?

    I am trying to move OVR playercontroller. It is not a child of something else.

    I tried to re-write "position" as a localPosition, but it is not working as well :(