04-18-2025 08:52 AM
https://developers.meta.com/horizon-worlds/learn/documentation/typescript/api-references-and-example...
The other day I took way too long trying to get these 2 example snippets to work
1. Teleport a Player snippet, I couldn't get it to work. It just fails. I tried a lot of variations. Is there some secret spell I'm supposed to cast before running these snippets?
2. Attach an Entity to Player Snippet : I tried so many variations of this it's ridiculous, I could not get this code working. I deducted it's probably something with the properties of my entity, so I tried so many things, the only thing that was attached to my player was frustration.
These snippets really made me questions my abilities to problem solve.
The most frustrating thing is seeing console logs after the code quietly fails with no explanation.
I really want to learn this stuff. I feel like there's some obvious thing I'm missing that's so obvious it was left out of the documentation.
04-18-2025 09:00 AM - edited 04-18-2025 09:35 AM
For the teleport script, it will only work on a local script because this.world.getLocalPlayer will return the server player I believe on a default script. It's best to use a trigger to test this to get the player reference. Also make sure you have custom player movement turned on in player settings.
It is kinda a confusing name because there is a teleport function on spawn point but this sets the players position directly.
For the attach one. Same as the other. get local player only works on a local script. Also make sure this script is attached to an entity that is set to be attachable. Also make sure the entity is collidabe. To get the player reference for this I would do it on grab start.
04-18-2025 09:55 AM
Thank you for the response @gausroth , my hats off to you.
It's still kind of confusing.
as soon as I turned on "custom player movement" my script worked for teleporting. It's kind of weird to not throw some error if some hidden switch isn't turned on in the editor.
I'll revisit the attachable script sometime soon too. It seems there's a lot of caveats when it comes to doing some of the most basic things.
Thanks again!
04-20-2025 01:30 PM
Hello Drew,
I have recorded two YouTube videos for you that explain those two key concepts in horizon.
- Teleportation: https://youtu.be/x5Qi8K9pzFA
- Attach Object: https://youtu.be/q6FSXdQlW4k
Let me know if these two videos help, or if you are still stuck.
04-20-2025 02:03 PM
Wow, I feel like a star! These are great videos I did manage to get this working the other day. I think your videos are going to help some people out. I'll subscribe to your channel so hopefully I can see videos before I run into issues. 🙂