Help for 2d Jump

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:

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;
        this.entity.translate(0,gravidade * dt,0);
    if(estanochao === true){
        if ( ) {
    if ( ) {
        this.entity.translate(-velocidade * dt,0,0);
    if ( ) {
        this.entity.translate(velocidade * dt,0,0);


Thank you very much.

If there are errors, please use Debugging to investigate it:

Your question is not specific enough, you need to be more clear on what is your exact problem, what you’ve tried and what goes exactly not as planned.

Good morning my friends,
I’ll try to be more specific then …
I tried to make my character jump but not very good,
He is varying the jump, in a strange way because I do not know how it is done here in PlayCanvas. I would like to know the correct way to do this please.
And what about the collision …
It is not happening properly, as there are times when he enters the ground and when he falls off the platform he enters the platform.
If you can help me, I’ll be grateful.