How to Teleport

Hello,
Goodday!
I have a simple question i think, because i m a beginner.
I have in a Room a table with CityOnTable object (in this object there are more objects like buildings, road, etc) on the table. I also have CityReal thats is the same as CityOnTable but is scaled x 1000.
200459-knipsel.jpg

Now i want to use my Quest 2 controller to focus and click (teleport) on the CityOnTable with the result that i teleport to that coordinate(location) in CityReal.

I tried something like this, but its long not good enough.

Code (CSharp):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Teleport : MonoBehaviour
{
 
    public void OnTriggerEnter(Collider other)
    {
        other.transform.position = transform.position.x *1000,transform.position.y *1000;
 
 
    }
}

And enabled a trigger on the CityOnTable object and place the above script in this object.
200460-knipse1l.jpg

Can someone help me with this?
best regards

I’ve updated this code to make it simpler. Might be worth checking back if you’re trying to adapt it…

It might be worth having a think about what you want here. For example, can you click on the side of a building? What happens if you do? Can the player teleport to the roof of a building? Perhaps the player can only click on a roadway. That seems the best to me. In that case, you would put this code on the ground game object in your CityOnTable. You can then adapt the following script:

using UnityEngine;

public class Teleport : MonoBehaviour
{
    Vector3 cityReal;

    private void Awake()
    {
        cityReal = GameObject.Find("CityReal").transform.position;
    }

    void OnMouseDown()
    {
        print(GetTeleportPosition(Input.mousePosition));
    }

    Vector3 GetTeleportPosition(Vector3 mousePos)
    {
        float scaleFactor = 1000;
        RaycastHit hit;

        Ray ray = Camera.main.ScreenPointToRay(mousePos);
        Physics.Raycast(ray, out hit);
        Vector3 offset = (hit.point - hit.collider.gameObject.transform.position);
        return offset * scaleFactor;
    }
}    

Place this code on the CityOnTable ground GameObject.

The Awake routine needs to find CityReal in your game. The OnMouseDown checks for a left mouse button press and gets the teleport position back, which it prints to the console. The Method called GetTeleportPosition takes in the mouse position, does a raycast to find out where it hit the road. It then finds out how far it is from the transform position of CityOnTable, and scales it up by scaleFactor.

Make sure that you don’t have the same code on the floor of the main city otherwise you could be teleported to who knows where…

As an extension task, you might want to think about CityReal being a separate scene to make sure player scale and mass are correct, as well as keeping each scene manageable. If you’re not sure how to do that, it might be worth raising a second question, rather than overloading this one. It will involve sharing values between scenes, which is an entirely different matter.

Hope this helps…