Forum Discussion

Drewls's avatar
Drewls
Start Partner
9 months ago

Example Scripts

https://developers.meta.com/horizon-worlds/learn/documentation/typescript/api-references-and-examples/example-scripts-library

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. 


4 Replies

  • 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.

     

    • Drewls's avatar
      Drewls
      Start Partner

      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! 

    • Drewls's avatar
      Drewls
      Start Partner

      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. 🙂