This tutorial helped me so much. Only issue I encountered was due to the fact that I was using a custom player controller instead of Rigidbody. For those in a similar situation: You can use an IEnumerator block which adds a short delay before you transport which allows you to use a custom controller without having to deactivate the player controller. This is what I used: IEnumerator Teleport() // this sets a delay for the teleport between each line of code so that it doesnt execute too fast. { yield return null; // you could set this for milliseconds/seconds with "WaitForSeconds", but returning null skips one frame. player.position = destination.position; yield return null; } Then I will call in the collider if statement like so: void OnTriggerEnter(Collider other) { if(other.CompareTag("Player")) { StartCoroutine("Teleport"); } }
Great tutorial, thanks! If you have a problem with getting it to work with different character controller, try this: using System.Collections; using System.Collections.Generic; using UnityEngine; public class TeleportPlayer : MonoBehaviour { public Transform destination; private void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { // Teleport the player to the destination other.transform.position = destination.position; } } } This way you could do it without referencing the object from the scenes such as while using clones in menager.
I'm moving with an XR rig called 'XR Origin (XR Rig)' instead of a 'Player' model, with a character controller underneath it. Would my script in the "comparetag" change? Any help would be AMAZING
hi when i try to add the script to my cube it says cant add script beacuse class cannot be found make sure there are no compile errors and that the file name and class name match
Hello, I'm also doing a VR project for my college. I'm having a problem where the player can teleport to the destination, but grabbed objects will always drop to the ground. Does yours work with retaining grabbed object?
Thank you for the great tutorial! What template did you use this? First Person? 3D URP? I tried to do your tutorial in a VR setup. I had an orb which I labled the receiver; it was a sphere with a sphere collider and a XR Origin rig which I tried to use as the player. I'm new to Unity so I'm sure I missed a lot of things. Anyhow, your solution is eloquent and simple, and I'm wondering where I went wrong. The script kept getting rejected.
You would use a coroutine for that. I recommend looking up how to start coroutines and how to use "yield return new WaitForSeconds(Amount of seconds);"
Right click your assets and click creat C# script or creat script and name it. Then your just nead to dubbel click the scrip and then it should open. if not you nead to download some thing like Visual Studios and code in there. Hop this helps
Finally A simple but yet working Mechanic
exactly what I needed and so so so simple thank you!
This tutorial helped me so much. Only issue I encountered was due to the fact that I was using a custom player controller instead of Rigidbody. For those in a similar situation:
You can use an IEnumerator block which adds a short delay before you transport which allows you to use a custom controller without having to deactivate the player controller. This is what I used:
IEnumerator Teleport() // this sets a delay for the teleport between each line of code so that it doesnt execute too fast.
{
yield return null; // you could set this for milliseconds/seconds with "WaitForSeconds", but returning null skips one frame.
player.position = destination.position;
yield return null;
}
Then I will call in the collider if statement like so:
void OnTriggerEnter(Collider other)
{
if(other.CompareTag("Player"))
{
StartCoroutine("Teleport");
}
}
how do you make it where your rigiged body doest go crazy when I hit a wall
nvm
I wrote the script out but the Destination options and stuff dont show
How do you press a certain button while looking at a certain object to teleport somewhere?
You are awesome as always. Just to the point.
Great tutorial, thanks! If you have a problem with getting it to work with different character controller, try this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TeleportPlayer : MonoBehaviour
{
public Transform destination;
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
// Teleport the player to the destination
other.transform.position = destination.position;
}
}
}
This way you could do it without referencing the object from the scenes such as while using clones in menager.
I’m pretty sure I did everything right but it’s not teleporting when my player comes in contact with the box collider
did ya fix it
I get an error message in the console saying that "player" is not defined, how can I fix this?
add player tag to your player controller / watch Brackeys
@@mikdailyreview5277 thank u
I'm moving with an XR rig called 'XR Origin (XR Rig)' instead of a 'Player' model, with a character controller underneath it. Would my script in the "comparetag" change? Any help would be AMAZING
hi when i try to add the script to my cube it says
cant add script beacuse class cannot be found make sure there are no compile errors and that the file name and class name match
you changed the script name in the editor / make sure the scripts name is the same in both visual studios and the unity editor
@@mikdailyreview5277 I quit unity 3 months ago I'm a full time gamer now and I'm trying to become famous on youtube
Great job man! Thanks!
Works perfectly, thank you very much.
it not work with ready player me avatar
Brilliant, thank you very much. Works perfectly.
hello
i wasnted to ask if "playerg" in the script should be changed to the name of the player gameobject in the project
?
thank you very much! this video helped me when I detected a teleportation bug in my VR game
Hello, I'm also doing a VR project for my college. I'm having a problem where the player can teleport to the destination, but grabbed objects will always drop to the ground. Does yours work with retaining grabbed object?
Thanks this worked :)
Thx alot. I did another thing but setActive is the solution 👍
Edot: im so happy right now. Rly thanks for thks 🙂
thanks! the ways to fix it helped too!
I found the video to be very useful. I would love to see more simple game mechanics like this.
thank you soo much it fixed a magor problem i had thanks!
im so glad he is not a pycopath and uses dark mode
Bro wht
Thank you. its super effective
thank you, this was very helpful!
Simple thanks!
Thank you for the great tutorial! What template did you use this? First Person? 3D URP? I tried to do your tutorial in a VR setup. I had an orb which I labled the receiver; it was a sphere with a sphere collider and a XR Origin rig which I tried to use as the player. I'm new to Unity so I'm sure I missed a lot of things. Anyhow, your solution is eloquent and simple, and I'm wondering where I went wrong. The script kept getting rejected.
very useful and easy to understand video
Found it very helpful. Thanks so much.
how to add player into unity?
not working ):
How do you wait longer? You know for an animation to finish before being able to move?
You would use a coroutine for that. I recommend looking up how to start coroutines and how to use "yield return new WaitForSeconds(Amount of seconds);"
how do i get into the script
Right click your assets and click creat C# script or creat script and name it. Then your just nead to dubbel click the scrip and then it should open. if not you nead to download some thing like Visual Studios and code in there. Hop this helps
BEST VID
Thank you
great guide thx
nice
THANKS