The Code to Teleport

So I’m wanting to teleport my character to a box so I can play a jumpscare but I don’t really know how to code so I was wondering if I could get some help with figuring it out? I just want to teleport my character into the box after it touches a certain entity.

Hi @Gabriel_Alan_Alolor and welcome!

The page below can help you to create a trigger entity.

On your trigger entity you can add a script to teleport the player entity to the position of another entity. If you give the other entity the name TeleportPoint and the player entity the name Player, you can use the example code on your trigger entity.

var Teleport = pc.createScript('teleport');

// initialize code called once per entity
Teleport.prototype.initialize = function () {
    this.entity.collision.on('triggerenter', this.onTriggerEnter, this);

    this.teleportPoint ='TeleportPoint');

Teleport.prototype.onTriggerEnter = function (entity) {
    if ( === 'Player') {

Okay so, I put in the code into my trigger entity and it is not working, I either put the script into the enemy capsule hitbox, or I put the script into the actually enemy entity and it gives me an error about “on” being undefined

Okay so I just clicked your link and totally forgot to make the trigger entity. So now I have it made but it is still saying an error but now its saying entity is not defined.
if ( === ‘Player’) {

Sorry, I made a mistake in my code and I have now corrected it.

Okay so, it teleports me now, just it is not teleporting me into the box, it teleports me above my maze when the TeleportPoint is not anywhere near

Can you share the editor link of your project so I can take look when I have some time?

Also update, I just moved the tp box into the air where I teleport because I thought it would be easier but its just a big box in the sky…

It looks like the teleporting works now, so I’m not sure what your current issue is.

Okay, thank you for the help, I just want one more thing with help if that’s okay, would I be able to put a code to where when my player teleports to the entity, it switches cameras?

You can disable the default camera entity and enable another camera entity.

What is the use case?

What do you mean by use case?

For what do you want to switch to another camera?

I want to switch the players view to the entity camera that I have placed on the entity that is in the jumpscare box, basically when I get in contact with the entity roaming the maze, I teleport to the box and change the camera to the one connected to the entity