[SOLVED] Entity jump on walls

I have found no tutorials concerning wall jumping, I am developing a 2d game, and it would be great to have a wall jump function. what would a ideal script be.
https://playcanvas.com/editor/scene/1032540
Down below is the script I am using, please reply if you have a script that allows to wall jump

 var from = this.entity.getPosition();
    var to = new pc.Vec3(from.x, from.y - this.entity.getLocalScale().y, from.z);
    var canJump = false;
    var result = this.app.systems.rigidbody.raycastFirst(from, to);
    
    
    if(result)
    {
        canJump = true;
    }
    else
    {
        canJump = false;
    }
    
    
    if(this.app.keyboard.wasPressed(pc.KEY_W) && canJump)
    {
        this.entity.rigidbody.applyImpulse(0,1000,0);
    }
};
1 Like

I have found no tutorials concerning wall jumping, I am developing a 2d game, and it would be great to have a wall jump function. what would a ideal script be.
https://playcanvas.com/editor/scene/1032540

here is the code I have

 //Jumping
    var from = this.entity.getPosition();
    var to = new pc.Vec3(from.x, from.y - this.entity.getLocalScale().y, from.z);
    var canJump = false;
    var result = this.app.systems.rigidbody.raycastFirst(from, to);
    
    
    if(result)
    {
        canJump = true;
    }
    else
    {
        canJump = false;
    }
    
    
    if(this.app.keyboard.wasPressed(pc.KEY_W) && canJump)
    {
        this.entity.rigidbody.applyImpulse(0,1200,0);
    }

I have posted several times. I am still looking for a wall jumping script
. I have already tried to tweak the code, it only makes it jump higher…
I am still new to the game engine, and java script. although I am slowly learning
https://playcanvas.com/editor/scene/1032540
here is the code

    var to = new pc.Vec3(from.x, from.y - this.entity.getLocalScale().y, from.z);
    var canJump = false;
    var result = this.app.systems.rigidbody.raycastFirst(from, to);
    
    
    if(result)
    {
        canJump = true;
    }
    else
    {
        canJump = false;
    }
    
    
    if(this.app.keyboard.wasPressed(pc.KEY_W) && canJump)
    {
        this.entity.rigidbody.applyImpulse(0,1200,0);
    }

Please don’t post about the same question multiple times. If anything, please bump the old post.

ok, Sorry.

Hello @Yes_Boi! Can you explain a little better what you want the wall jump to look like? With the current code you only check whether there is an obstacle on the bottom. With a wall jump you also have to check if there is an obstacle in the front. However, I am not a wall jump expert.

1 Like

Greetings @Albertos well, A ideal wall jump would be where you can always jump when you are in contact with a wall or the ground, for example you would be able to jump from wall 1 if it is located at (0, 10, 0) to wall 2 that is located at (5, 15, 0)

Okay, then I would make a second raycast forward. If it has a result (so there is a wall) and the raycast down has no result (so the character is in the air) then I would turn my character 180 degrees and repeat the jump action.

Could you explain it in more detail.

I don’t know what is ‘deta’, sorry.

R u looking for this?
chrome-capture

Here i modified your code...(Click to Expand)
var Heyehyey = pc.createScript('heyehyey');

// initialize code called once per entity
Heyehyey.prototype.initialize = function() {
    
};

// update code called every frame
Heyehyey.prototype.update = function(dt) {
       if(this.app.keyboard.isPressed(pc.KEY_D)){
    this.entity.rigidbody.applyForce(1700,0,0);}
    
       if(this.app.keyboard.isPressed(pc.KEY_A)){
    this.entity.rigidbody.applyForce(-1700,0,0);} 
    
    
    /*
       if(this.app.keyboard.isPressed(pc.KEY_SHIFT)){
    this.entity.rigidbody.applyForce(-1800,0,0);} 
    
       if(this.app.keyboard.isPressed(pc.KEY_SHIFT)){
    this.entity.rigidbody.applyForce(1800,0,0);} 
    */
    
    //Jumping
    var canJump = false;
    var from = this.entity.getPosition();
    var to = new pc.Vec3(from.x, from.y - this.entity.getLocalScale().y, from.z);
    var result = this.app.systems.rigidbody.raycastFirst(from, to);
    var toLeftSide = new pc.Vec3(from.x - this.entity.getLocalScale().x, from.y, from.z);
    var resultLeftSide = this.app.systems.rigidbody.raycastFirst(from, toLeftSide);
    var toRightSide = new pc.Vec3(from.x + this.entity.getLocalScale().x, from.y, from.z);
    var resultRightSide = this.app.systems.rigidbody.raycastFirst(from, toRightSide);
    
    if(result || resultLeftSide || resultRightSide)
    {
        canJump = true;
    }
    else
    {
        canJump = false;
    }
    
    
    if(this.app.keyboard.wasPressed(pc.KEY_W) && canJump)
    {
        if(resultLeftSide && !result)
            this.entity.rigidbody.applyImpulse(1000,1200,0);
        else if(resultRightSide && !result)
            this.entity.rigidbody.applyImpulse(-1000,1200,0);
        else if(result)
            this.entity.rigidbody.applyImpulse(0,1200,0);
    }
    
};

// swap method called for script hot-reloading
// inherit your script state here
// Heyehyey.prototype.swap = function(old) { };

// to learn more about script anatomy, please read:
// http://developer.playcanvas.com/en/user-manual/scripting/
1 Like

thank very much

1 Like

One more fix for you…
image
To prevent the character moving toward edge like this

Change following setting for your character…
image

thank you

How did you do that smooth falling?

I can see that it’s linearDamping, but it still jumps like natural.

Could you pls explain it?