uh now it just rises me into the air my brain hurts
Then probably you have to adjust the values. For example try to change 500 to 100.
ill try
it still rises me
But does it help a bit? Did you already try 10 instead of 100? Please a little more effort from your side.
here i will show u my code
var Jump = pc.createScript('jump');
// initialize code called once per entity
Jump.prototype.initialize = function() {
};
// update code called every frame
Jump.prototype.update = function(dt) {
this.timer += dt;
if (this.timer > 2 && this.app.keyboard.isPressed(pc.KEY_SPACE)); {
this.timer = 0;
this.entity.rigidbody.applyImpulse(0, 100, 0);
}
};
For the next time if you want to sent your code, please use the code highlight option and add your code inside the signs.
If you share a link of your project, someone can take a look to see what’s going wrong.
oh so that is how you do that ok
There were two problems:
-
this.timer
has to be added to the initialize function otherwise the result isNaN
. -
You made a mistake at the end of your if statement, that I also copied because I hadn’t seen it.
The code below solve this problems:
var Jump = pc.createScript('jump');
// initialize code called once per entity
Jump.prototype.initialize = function() {
this.timer = 0;
};
// update code called every frame
Jump.prototype.update = function(dt) {
this.timer += dt;
if (this.timer > 1 && this.app.keyboard.isPressed(pc.KEY_SPACE)) {
this.timer = 0;
this.entity.rigidbody.applyImpulse(0, 1000, 0);
}
};
thank you it works now. now just have to change how high i can jump but i can do that myself =)