[SOLVED] How to load new scene using collision?

I have tried to write my own script multiple times using the collision and change scene tutorials, and it never works. Does anyone know what to do?

Hi @yoforduder and welcome,

What do you mean load a new scene using collision? Maybe using a trigger so the player steps in it and then a scene is loaded?

For triggers check this example tutorial: Collision and Triggers | Learn PlayCanvas

When you have your trigger in place head to the Scene changing tutorials/examples to add the required code: Tutorials | Learn PlayCanvas

Hope that helps!

1 Like

I attempted to make my own trigger script and it works? It is supposed to load into the “Menu” scene but instead every time I walk into the trigger, it teleports me high in the air.

Here is the code

var Trigger = pc.createScript('trigger');

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

Trigger.prototype.onTriggerEnter = function(entity) {
this.app.scenes.changeScene('Menu');
};

Hi @yoforduder! Can you share the editor link of your project, so someone can take a look?

Here is the link:

Link

The scene I’m trying to make it work on is called “Beggining”

Your script doesn’t look like what you shared here.

image

I have figured out the issue;

I had 2 different scripts with the same name and the one with the scene change code was the only one showing up in the editor. I fixed this by deleting both and making a new one. Thank you for your help.

2 Likes