Hello
I am new to the playcanvas environment. Recently I have started watching tutorials on YouTube, trying to learn how to use the environment.
I was making good progress until I came onto script files. I am having issues getting the script files to run on my own projects.
Here is a run down and an example of what I am doing:
- Creating a new project and adding a cube to the middle of the canvas.
- Adding a script component to the cube in the Hierarchy section.
- Adding a script titled “move.js” to the cube.
- Typing in the following code (which I acquired from this tutorial -> https://www.youtube.com/ watch?v=VpJxc_iRmeM):
pc.script.create(‘move’, function (app) {
// Creates a new Move instance
var Move = function (entity) {
this.entity = entity;
};
Move.prototype = {
// Called once after all resources are loaded and before the first update
initialize: function () {
},
// Called every frame, dt is time in seconds since last update
update: function (dt) {
if(app.keyboard.isPressed(pc.i nput.KEY_RIGHT)){
this.entity.translateLocal(0.1 ,0,0);
}
if(app.keyboard.isPressed(pc.i nput.KEY_LEFT)){
this.entity.translateLocal(-0. 1,0,0);
}
if(app.keyboard.isPressed(pc.i nput.KEY_UP)){
this.entity.translateLocal(0,0 .1,0);
}
if(app.keyboard.isPressed(pc.i nput.KEY_DOWN)){
this.entity.translateLocal(0,- 0.1,0);
}
}
};
return Move;
});
- I am then launching the project and the tutorial says that while pressing the arrow keys the cube should move however nothing is happening.
I have tried to run several script files on different elements and nothing is working. I am launching the programs and then opening my Google Chrome navigator to see what files are running on the page and none of my script files are running.
I am following the exact instructions given on tutorials on your site as well as the YouTube video; could you please explain what could be the potential problem or even have a look at my public project to see what is going on? Here is a link to my project -> https://playcanvas.com/ project/447098/overview/move
I am very eager to get rolling and adding script files to my environment and really appreciate your time and insight and look forward to hearing back from you guys!
Thank you so much,
Suraj Tirupati