How to create some sort of edge compensation when a player (capsule) is standing on an edge

Hello

Currently in ammo when a capsule collision entity stands on a edge it falls off automatically when half of its diameter leaves the edge. I want to make it so the capsule only falls when its entire diameter leaves the edge. Is this possible to achieve without a raycast? Maybe setting some sort of a box collision entity or something underneath the player? But I can’t figure out the logic. I would appreciate any guidance :slight_smile:

What I want to achieve (the right picture):

1

Thanks!

Hi @nasjarta,

Hmm, that’s an interesting problem, using a cylinder as collision shape I imagine isn’t an option here right?

1 Like

I want to try to keep it as a capsule if it’s possible.

Here is a link of what I want to achieve: (Thanks to pixelpros for the link) https://lightbug14.gitbook.io/ccp/fundamentals/untitled/character-actor/stable-movement-features#edge-compensation

There it says is “What edge compensation does is to lift up the capsule, simulating a cylinder shape.” But then again I find it hard to understand the logic to implement this.

The suggestion of @Leonidas makes me a bit doubtful whether I understand the problem correctly, but I think the same problem is discussed in the topic below, so maybe it can help you.

https://forum.playcanvas.com/t/solved-making-first-person-character-walk-through-stairs/

1 Like

Hello

I didn’t understand the solution of that topic unfortunately.

Here is a better diagram of what I mean:

I wonder if it is possible to achieve without a raycast.

That’s is the solution that I also use in my game, but I don’t use physics in my game. Using a raycast does not block the gravity and if you make a 3D game where the player can rotate 360 degrees a single raycast will not be enough.

If I have some time I can try to make an example project with one of the solutions from the other topic.

2 Likes

Yep in a 3D game especially, the player base is going to require many raycasts to check the circumference of the player. I was thinking there could be a more easier way (like simulating a certain shape underneath the player - like in the example I linked) or extending the capsule’s collision diameter.

I would appreciate that. If I can understand the logic of how to achieve this I will give it a shot at implementing too.

I think the solution of @Leonidas in the post below is really easy to implement. What are the current settings of your rigidbody component and how do you move your player? Can you show this or can you share a link to your project?

1 Like

Here: https://playcanvas.com/project/818004/overview/smoothfalling

For testing purposes. Has a third person debug when you press X. I could give you read and write permissions to it if you would like.

Right now the friction of the rigidbody is 0.25.

As far as I understand the solution is to change the friction by script when the player is not moving. This prevent the player is sliding off. It will look something like below.

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

        this.entity.rigidbody.friction = 0.25;
    }
    else {
        this.entity.rigidbody.friction = 1;
    }

1 Like

Hello

Thanks for the help but unfortunately this is not what I am looking for, it doesn’t work as I expected.

Your solution from the other topic by Leonidas is very good for moving/standing on ramps though.

Did a quick modification:

if (x !== 0 && z !== 0) {
        force.set(x, 0, z).normalize().scale(this.movementSpeed);
        this.entity.rigidbody.applyForce(force);
        this.entity.rigidbody.friction = 0.25;
    }
    else {
        this.entity.rigidbody.friction = 1;
    }
console.log(this.entity.rigidbody.friction);
1 Like

I thought this was exactly what you wanted to achieve?

1 Like

Sorry for being confusing, i may have explained the problem wrong.

Basically when you change the players collision to a box or cylinder it does what i want (the player can still stand on the edge of a platform without sliding off/falling). However when the players collision is a capsule it slides off/falls as soon as the bottom is not touching anymore.

I want to achieve the same effect as the box/cylinder but instead as a capsule. If possible I would like to do this without a raycast because I thought maybe there could be a way to simulate another shape (like having a separate collider under the player that only activates once the player is standing on an edge? Or some sort of method that extends the capsules lower collision diameter.

I had the idea that a box collider will tip over when it is over halfway?

It would be nice if you had an example project showing the problem, because with using a first person controller in your current scene I don’t see this anywhere.

1 Like

Hey feel free to use this I made some changes: https://playcanvas.com/project/818004/overview/smoothfalling

When you launch press the X key to debug in third person mode so you can see what I mean. I changed the collision to a cylinder (now if you move over the edge of a platform it does not fall off). You will see what I mean.

1

Like Leonidas pointed out - I want to achieve the same effect with a capsule and not cylinder.

Perhaps it is an option to temporarily switch to a kinematic rigidbody or to make the collider larger than is actually necessary? I don’t think there is a simple solution without having to make concessions. And it’s hard to think along with you because I don’t exactly understand why the current solution with changing the friction is not enough.

1 Like

The friction solution only works to some extent it is not what i want exactly. It still slides off the platform but has better grip, does not extend the collision body fully.

I want to be able to achieve what is on the picture but with a capsule collision instead. There is a another solution from another link that I provided where the body is lifted up slightly so it simulates a cylinder type collision feel but I have trouble understanding its logic.

Can you tell me why you can’t use a cylinder? Maybe we can find a solution for that problem.

1 Like

The cylinder doesn’t collide as well with walls and roofs it feels a bit rigid and does not give the same really good feel as the capsule.

1

Could I do something like this? What do you think? Would this have any problems? Having a mini collider underneath the player?

@Albertos
@Leonidas - sorry for ping but I would like your opinion on this too :slight_smile:

With a cylinder it would be more difficult to climb a slope, but apart from that it should work the same as a capsule.

This feels like a compromise between cylinder and capsule. That may be a good way to solve your problem but I’m afraid it will give you the problems of both options but to a lesser extent.

1 Like