You miss a second bracket, try this for your initialize method:
Jumping.prototype.initialize = function(){
if (this.app.keyboard.wasPressed(pc.KEY_SPACE)) {
this.entity.rigidbody.applyImpulse(pc.Vec3.UP.scale( 10 /* the amount of power*/));
}
}
@Gabriel_Dobrzynski developing a game in PlayCanvas requires you to have at least some knowledge in JavaScript programming. WIthout it, the experience will feel dounting and you will struggle to do even the basic things. I recommend brushing up your JS skills first and complete a good JS tutorial.
For example https://javascript.info/ looks good, althtough I haven’t personally tried it. You definitely want to complete the Part 1 and you can even do it inside PlayCanvas, without having to write HTML files.
Hey all, I have fixed this problem added more onto it but when you go in launch without pressing anything you fly all the way up. What is happening? The new code I added:
var Jumping = pc.createScript('jumping');
// initialize code called once per entity
Jumping.prototype.initialize = function(){
this.app.keyboard.on(pc.EVENT_KEYDOWN, this.onKeyDown, this);
this.app.keyboard.on(pc.EVENT_KEYUP, this.onKeyUp, this);
};
// update code called every frame
Jumping.prototype.update = function(dt) {
this.app.keyboard.on(pc.EVENT_KEYUP, this.onKeyUp, this);
this.entity.rigidbody.applyImpulse(0, 5, 0);
};
// swap method called for script hot-reloading
// inherit your script state here
// Jumping.prototype.swap = function(old) { };
// to learn more about script anatomy, please read:
// http://developer.playcanvas.com/en/user-manual/scripting/