[SOLVED] Best settings dynamic rigidbody for player entity

I had the idea to see if I can use physics for my game. I started with the settings as below.

image

Here I run into the problem that the player is sliding slightly. Setting the Linear Damping to 1 solves this, but then the player doesn’t fall down anymore.

Also I like to know how to check the current velocity, because probably it could be a solution to adjust the settings at runtime. I thought I could do something like below, but it looks like thats not the case.

console.log(this.entity.rigidbody.velocity.y);

Maybe use friction? That usually works for me

1 Like

Hi Albertos, in order to get the entity’s velocity, try replacing velocity with linearVelocity

console.log(this.entity.rigidbody.linearVelocity.y);

As for linear damping I usually set my player’s linearDamping to 0, and manually add linear damping on the X and Z axis like so:

var dampingForceX = -10 * this.entity.rigidbody.linearVelocity.x ^ dt;
var dampingForceZ = -10 * this.entity.rigidbody.linearVelocity.z ^ dt;

this.dampingForce = new pc.Vec3(dampingForceX, 0, dampingForceZ);

this.entity.rigidbody.applyForce(this.dampingForce);

This way the entity falls naturally under the effect of gravity.

Lol, i just increase the gravity

Thanks for your reply. I’ve tried your suggestions, but without success so far.

Oh, hmm

@Leonidas I see in another post you use .length(). Do I need to do that also if I want to check the Y-axis only? What would that look like?

No, for a single axis just do what you do.

Length() is used as an easy check for all three axis.

Edit: just make sure to check the absolute value, like this:

Math.abs(velocityOnY) < 0.01

Something like this?

var velocityOnY = Math.abs(this.entity.rigidbody.linearVelocity.y);
1 Like

Below the best settings for me so far. I apply a force between 20 and 100, based on the input of the player. No need to tweak physics with script.

image