Skip to main content

How to move one object to another object's postionposition

Cleaned up the code block, removing unnecessary blank lines and providing proper indentation so the whole block is treated as code.
Source Link

So I'm want to move one game object  (my player) to the position of another game object, on keyDown. I'm just not sure how to reference the position of the object which is where I want my player to move(or teleport) to.

I know a couple different was to move my player, but I don't know what variable or statement I would use to reference the other objects position.

(Also the thing I'm teleporting to is not moving). I really appreciate any help you can give me.

usingpublic System.Collections;

using System.Collections.Generic; using UnityEngine;

public class GetInCar : MonoBehaviour { public GameObject player; public GameObject car; //public Camera cam1;

voidclass StartGetInCar (): 
 MonoBehaviour {
}    public GameObject player;
    public GameObject car;
    //public Camera cam1;

    void OnMouseDown ()
  {
        if (Input.GetKey (KeyCode.Mouse0)) {
    {
        player.transform.rotation = car.transform.rotation;
            print("MovedToCar");
            GameObject.Find ("Player").GetComponent<CharacterController> ().enabled = false;

            //cam1.enabled = true;
        }
    }
}

}

So I'm want to move one game object(my player) to the position of another game object, on keyDown. I'm just not sure how to reference the position of the object which is where I want my player to move(or teleport) to.

I know a couple different was to move my player, but I don't know what variable or statement I would use to reference the other objects position.

(Also the thing I'm teleporting to is not moving). I really appreciate any help you can give me.

using System.Collections;

using System.Collections.Generic; using UnityEngine;

public class GetInCar : MonoBehaviour { public GameObject player; public GameObject car; //public Camera cam1;

void Start () 
 {
}



void OnMouseDown ()
 {
    if (Input.GetKey (KeyCode.Mouse0))
    {
        player.transform.rotation = car.transform.rotation;
        print("MovedToCar");
        GameObject.Find ("Player").GetComponent<CharacterController> ().enabled = false;

        //cam1.enabled = true;
    }
}

}

So I'm want to move one game object  (my player) to the position of another game object, on keyDown. I'm just not sure how to reference the position of the object which is where I want my player to move(or teleport) to.

I know a couple different was to move my player, but I don't know what variable or statement I would use to reference the other objects position.

(Also the thing I'm teleporting to is not moving). I really appreciate any help you can give me.

public class GetInCar : MonoBehaviour {
    public GameObject player;
    public GameObject car;
    //public Camera cam1;

    void OnMouseDown () {
        if (Input.GetKey (KeyCode.Mouse0)) {
            player.transform.rotation = car.transform.rotation;
            print("MovedToCar");
            GameObject.Find ("Player").GetComponent<CharacterController> ().enabled = false;

            //cam1.enabled = true;
        }
    }
}
added 519 characters in body
Source Link
nova nanite
  • 381
  • 1
  • 7
  • 19

So I'm want to move one game object(my player) to the position of another game object, on keyDown. I'm just not sure how to reference the position of the object which is where I want my player to move(or teleport) to.

I know a couple different was to move my player, but I don't know what variable or statement I would use to reference the other objects position.

(Also the thing I'm teleporting to is not moving). I really appreciate any help you can give me.

using System.Collections;

using System.Collections.Generic; using UnityEngine;

public class GetInCar : MonoBehaviour { public GameObject player; public GameObject car; //public Camera cam1;

void Start () 
{
}



void OnMouseDown ()
{
    if (Input.GetKey (KeyCode.Mouse0))
    {
        player.transform.rotation = car.transform.rotation;
        print("MovedToCar");
        GameObject.Find ("Player").GetComponent<CharacterController> ().enabled = false;

        //cam1.enabled = true;
    }
}

}

So I'm want to move one game object(my player) to the position of another game object, on keyDown. I'm just not sure how to reference the position of the object which is where I want my player to move(or teleport) to.

I know a couple different was to move my player, but I don't know what variable or statement I would use to reference the other objects position.

(Also the thing I'm teleporting to is not moving). I really appreciate any help you can give me.

So I'm want to move one game object(my player) to the position of another game object, on keyDown. I'm just not sure how to reference the position of the object which is where I want my player to move(or teleport) to.

I know a couple different was to move my player, but I don't know what variable or statement I would use to reference the other objects position.

(Also the thing I'm teleporting to is not moving). I really appreciate any help you can give me.

using System.Collections;

using System.Collections.Generic; using UnityEngine;

public class GetInCar : MonoBehaviour { public GameObject player; public GameObject car; //public Camera cam1;

void Start () 
{
}



void OnMouseDown ()
{
    if (Input.GetKey (KeyCode.Mouse0))
    {
        player.transform.rotation = car.transform.rotation;
        print("MovedToCar");
        GameObject.Find ("Player").GetComponent<CharacterController> ().enabled = false;

        //cam1.enabled = true;
    }
}

}

Source Link
nova nanite
  • 381
  • 1
  • 7
  • 19
Loading