I need wall running!

i want some one to code a wall running script for me beacause im stuck on it
and i looked at some other fourms but no code.
can someone please relpy with code if you can

Hi @BarleyStudios,

Before having your player controller running on walls, can you post some info on your current player implementation?

What kind of controller are you using, and how do you control its movement.

do you want me to show your the code?

Yes, feel free.

1 Like

Hello @BarleyStudios
I think it is possible to do wallrunning, I would love to see how you do it! :smiley:

ok.

var Player = pc.createScript('firstPersonMovement');

Player.attributes.add('camera', {
    type: 'entity',
    description: 'Optional, assign a camera entity, otherwise one is created'
});

Player.attributes.add('power', {
    type: 'number',
    default: 2500,
    description: 'Adjusts the speed of player movement'
});

Player.attributes.add('lookSpeed', {
    type: 'number',
    default: 0.25,
    description: 'Adjusts the sensitivity of looking'
});

// initialize code called once per entity
Player.prototype.initialize = function() {
    this.force = new pc.Vec3();
    this.eulers = new pc.Vec3();

    var app = this.app;

    // Listen for mouse move events
    app.mouse.on("mousemove", this._onMouseMove, this);

    // when the mouse is clicked hide the cursor
    app.mouse.on("mousedown", function () {
        app.mouse.enablePointerLock();
    }, this);

    // Check for required components
    if (!this.entity.collision) {
        console.error("First Person Movement script needs to have a 'collision' component");
    }

    if (!this.entity.rigidbody || this.entity.rigidbody.type !== pc.BODYTYPE_DYNAMIC) {
        console.error("First Person Movement script needs to have a DYNAMIC 'rigidbody' component");
    }
};

// update code called every frame
Player.prototype.update = function(dt) {
    var force = this.force;
    var app = this.app;

    // Get camera directions to determine movement directions
    var forward = this.camera.forward;
    var right = this.camera.right;


    // movement
    var x = 0;
    var z = 0;

    // Use W-A-S-D keys to move player
    // Check for key presses
    if (app.keyboard.isPressed(pc.KEY_A) || app.keyboard.isPressed(pc.KEY_Q)) {
        x -= right.x;
        z -= right.z;
    }

    if (app.keyboard.isPressed(pc.KEY_D)) {
        x += right.x;
        z += right.z;
    }

    if (app.keyboard.isPressed(pc.KEY_W)) {
        x += forward.x;
        z += forward.z;
    }

    if (app.keyboard.isPressed(pc.KEY_S)) {
        x -= forward.x;
        z -= forward.z;
    }

    // use direction from keypresses to apply a force to the character
    if (x !== 0 && z !== 0) {
        force.set(x, 0, z).normalize().scale(this.power);
        this.entity.rigidbody.applyForce(force);
    }

    // update camera angle from mouse events
    this.camera.setLocalEulerAngles(this.mouse.y, this.mouse.x, 0);
};

Player.prototype._onMouseMove = function (e) {
    // If pointer is disabled
    // If the left mouse button is down update the camera from mouse movement
    if (pc.Mouse.isPointerLocked() || e.buttons[0]) {
        this.mouse.x -= this.lookSpeed * e.dx;
        this.mouse.y -= this.lookSpeed * e.dy;
         this.mouse.y = pc.math.clamp(this.mouse.y,  -90,90);
    }
};

well i watched the untity tutorial on wall running and try to transform c# code to javascript code

1 Like

So, I don’t see anything specific to wall running, isn’t that the first person movement code as it is?

I don’t know of any code for wall running that you can use out of the box so you will have to transform the logic of that tutorial into working JS code.

One way I see of doing this, once the player has jumped on a wall, to do a raycast and get the wall normal. From that moment as long as the player is in touch with the wall you can apply a force from the player towards the wall surface.

That force will have the effect of making the player “stick” to the wall, get pulled to it.

If you don’t know where to start, check some of the example projects here that involve collisions, physics and raycasting:

https://developer.playcanvas.com/en/tutorials/

2 Likes

ok

hey, before i go, do you know how to code infinite terrain generation?

maybe, use code to detect wall touches as well, then have a variable for when it is touching the wall, use those vectors to add force the direction you want

Try searching the forum for older posts on that subject, if you don’t find an answer post a new topic about it.

2 Likes

i have video for the wall running

5 Likes

Is this PlayCanvas?

1 Like

yes

Can you link a project?

bro, this is sick!

2 Likes

btw, what is your account name on playcanvas?

1 Like

https://playcanvas.com/barleystudios

2 Likes

can you link the project i need wallrunning to motigate