[SOLVED] Normalize movement force along with the moving object

Hello, how should I calculate the final force/direction of the movement with respect to the moving object (on which the player is)

I calculate the velocity of the moving (tweened) object and
this.player.rigidbody.linearVelocity = this.velocity;
however, this method “adds” power only to the side in which the object/platform moves, for example:
the object moves forward - the player can also move forward more strongly
it does not apply to left/right/backward movement

I think that I should calculate and normalize the movement together from both the player’s and the platform’s side, but how to do it?

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

Thanks for any help

Can you not add the moving object/platform velocity to the existing velocity?

You mean
this.player...velocity = this.player...velocity + this.platform...velocity;
using .add() instead of
this.player...velocity = this.platform...velocity;?

const v = this.player.rigidbody.linearVelocity;
v.add(this.velocity);
this.player.rigidbody.linearVelocity = v;

Edit: Actually, that may be problematic thinking about it as that would add it each frame :thinking:

I actually don’t have a good answer if it’s mixing forces for input and velocity for external ‘forces’

Below related topics that may be useful.

I have already reviewed all possible examples and solutions and already handled slidings/bouncies/non sticks using teleport combined with detection when moving/idle, the problem is movement force, even PlayCanvas 3D HTML5 Game Engine has the same problem once you increase the mass of player (default is set to 1, once sat to 5 issue gets visible)

I wonder if it’s possible to work out the force or impulse needed to move the player a set distance/by the platform velocity (force = mass * acceleration). If you can work out the acceleration, you could work out the force/impulse

This is the only ‘playable’ solution I could achieve

if (this.player.onPlatform !== undefined && this.player.isMoving == true) {
    //Why 3? An average velocity based on player speed on each axis
    this.playerVel = 3;

    //Getting ratio of how much platform velocity increases over player average per axis
    this.addedZ = this.playerVel + Math.abs(this.velocity.z);
    this.ratioZ = 1 * this.addedZ / this.playerVel;
    this.addedX = this.playerVel + Math.abs(this.velocity.x);
    this.ratioX = 1 * this.addedX / this.playerVel;

    //Checking if velocity direction is negative or positive per axis
    this.objDirectionZ = Math.sign(this.velocity.z);
    this.playerDirectionZ = Math.sign(this.player.moveZ);
    this.objDirectionX = Math.sign(this.velocity.x);
    this.playerDirectionX = Math.sign(this.player.moveX);

        //Checking if player and platform 'moves' to the same direction and finally setting ratio
        if (this.objDirectionZ == this.playerDirectionZ && this.velocity.z !== 0 && this.ratioZ > 1) {
            this.player.velRatioZ = this.ratioZ;
        }
        //Checking if player and platform 'moves' to the same direction and finally setting ratio
        if (this.objDirectionX == this.playerDirectionX && this.velocity.x !== 0 && this.ratioX > 1) {
            this.player.velRatioX = this.ratioX;
        }

} else {
    //Default values if player is not moving or not on platform 
    this.player.velRatioZ = 1;
    this.player.velRatioX = 1;    
}

And then we add that to force

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

It’s not a perfect solution, going to the “opposite” side is still “faster”, that could be fixed, but otherwise it adds some realism