How to make the movement uniform regardless of the obstacle?

Hello, I am moving the player using forces, the following question arose, what is the best way to unify the player’s movement speed despite different obstacles? (Uphill, downhill, etc.)

The gravity I set is quite low (-40), so it is really difficult for the player to climb steeper objects, the default -9.8 is not suitable for me, because the player falls down too slowly

Is there some kind of measurement that can be taken in real time when encountering an obstacle?
It would be great to have such functionality and apply “this.moveForceDependingOnObstacle” not only for speed but also for animations, realistic.

Thanks for any information

For now, the solution: Gravity is changed depending on whether the player is still colliding with the last rigidbody that triggered collision start, this is not a perfect solution, level obstacles like ramps or jumping over platforms and similar works well, but the logic is not the same for stairs

PlayerAnimationHandler.prototype.onCollisionStart = function(result) {

    if (result.other.rigidbody) {

    this.canJump = true;

    this.lastCollider = result.other._guid;




PlayerAnimationHandler.prototype.onCollisionEnd = function(result) {

    if (result._guid == this.lastCollider) {




For something like this, I would be doing raycast to the floor and use the result normal to work out the slope angle/direction.

Once that is done, I can apply a force along the direction of the slope instead of into it.

1 Like


var raypos = this.entity.getPosition();
var start = raypos;
var end = new pc.Vec3(raypos.x, raypos.y - 1000, raypos.z);
    var result =, end);
        if (result) {

How to combine the received data together with the movement?

this.entity.rigidbody.applyForce(this.force.x * this.moveSpeed,this.player.downforce,this.force.z * this.moveSpeed);

this.force is calculated based on camera.forward/right and key presses

What I would do is cross the normal with the player’s right direction and that will give you a forward vector up the slop in the direction that the player is facing.

1 Like

Finally figured out how to use normal and give the appropriate force, but there is one problem, how to programmatically understand whether the player is going up or down?

After you do the cross product that I mentioned above, you can check the Y component to see if it is pointing up or down

1 Like