Good afternoon my friends,
I did a jump test for my game in 2d but it’s not good …
Could you help me see where it’s wrong?
Something that is strange is also the collision with the ground that is not very good.
Here is my code and the project:
https://playcanvas.com/project/460492/overview/projeto-base
var SMovimentosTeclado = pc.createScript('sMovimentosTeclado');
var estanochao = false;
var gravidade = -2;
// initialize code called once per entity
SMovimentosTeclado.prototype.initialize = function() {
this.entity.collision.on('collisionstart', this.onCollisionStart, this);
this.entity.collision.on('collisionend', this.onCollisionEnd, this);
};
SMovimentosTeclado.prototype.onCollisionStart = function(entity) {
estanochao = true;
};
SMovimentosTeclado.prototype.onCollisionEnd = function(entity) {
estanochao = false;
};
// update code called every frame
SMovimentosTeclado.prototype.update = function(dt) {
var velocidade = 3;
if(estanochao===false){
this.entity.translate(0,gravidade * dt,0);
}
if(estanochao === true){
if (this.app.keyboard.wasPressed(pc.KEY_SPACE) ) {
this.entity.translate(0,8*dt,0);
}
}
if (this.app.keyboard.isPressed(pc.KEY_LEFT) ) {
this.entity.translate(-velocidade * dt,0,0);
}
if (this.app.keyboard.isPressed(pc.KEY_RIGHT) ) {
this.entity.translate(velocidade * dt,0,0);
}
};
Thank you very much.