- #1
Xcrypt
- 21
- 0
Hello, I am a coder trying to build a game 2D rigid body physics engine.
So far I am working with an impulse-based approach and all is going pretty decent.
Everything does it's job, except one thing: friction acting on a rolling ball.
First I will explain how my collision resolution system works and then I will be more specific about the rolling ball.
My collision resolution system:
When a body hits another body, the collision detection system returns some info:
- a contactpoint : P
- a contactnormal : n
- a contacttangent : t
the next step is to resolve the velocities with an impulse-based approach
1) check the relative velocity of both bodies:
Vr = (v0+(w0 X (P-p0)) - (v1+(w1 X (P-p1)))
where
v: velocity of the body,
w: angular velocity of the body,
p: position of the body
X: vector/cross product
2) project Vr on the n & t to find out the relative velocity in contact coordinates
Vr_C.x= Vr ° n
Vr_C.y= Vr ° t
where
°: scalar/dot product
3) find out the required change in velocity along normal due to the collision
dV_C.x = -(1+restitution)(Vr_C.x)
4) find out the required change in velocity along tangent due to (static) friction
dV_C.y = -Vr_C.y
5) find the velocity per impulse applied at contactpoint along n & t
vpi_n= [ [((n X (P-p0))*iit_inv0) X (P-p0)] + 1/m0 + [((n X (P-p1))*iit_inv1) X (P-p1)] + 1/m1 ] ° n
vpi_t= [ [((t X (P-p0))*iit_inv0) X (P-p0)] + 1/m0 + [((t X (P-p1))*iit_inv1) X (P-p1)] + 1/m1 ] ° t
where
iit_inv: inverse moment of inertia tensor
m: mass
6) find the required impulsed we need to apply along n & t
reqI_n = dV_C.x / vpi_n
reqI_t = dV_C.y / vpi_t
7) In the last stage I do some extra fudgy math/physics for dynamic friction.
if(reqI_t > reqI_n*µ)
then reqI_t = reqI_n*µ
else if(reqI_t < -reqI_n*µ)
then reqI_t = -reqI_n*µ
where
µ: friction coefficient
The problem I have with rolling balls
When a ball is rolling over a flat surface, it's Vr_C.y seems to be very close to zero, causing no visible friction to act on the contactpoint.
where
Vr_C.y = (v+(w X (P-p)) ° t
It seems like the v (linear velocity) component and the (w X (P-p) component (linear velocity at P, due to rotation)
cancel each other out.
Have I gone wrong somewhere in my formulas?
How can this be explained?
Thanks for any help.
So far I am working with an impulse-based approach and all is going pretty decent.
Everything does it's job, except one thing: friction acting on a rolling ball.
First I will explain how my collision resolution system works and then I will be more specific about the rolling ball.
My collision resolution system:
When a body hits another body, the collision detection system returns some info:
- a contactpoint : P
- a contactnormal : n
- a contacttangent : t
the next step is to resolve the velocities with an impulse-based approach
1) check the relative velocity of both bodies:
Vr = (v0+(w0 X (P-p0)) - (v1+(w1 X (P-p1)))
where
v: velocity of the body,
w: angular velocity of the body,
p: position of the body
X: vector/cross product
2) project Vr on the n & t to find out the relative velocity in contact coordinates
Vr_C.x= Vr ° n
Vr_C.y= Vr ° t
where
°: scalar/dot product
3) find out the required change in velocity along normal due to the collision
dV_C.x = -(1+restitution)(Vr_C.x)
4) find out the required change in velocity along tangent due to (static) friction
dV_C.y = -Vr_C.y
5) find the velocity per impulse applied at contactpoint along n & t
vpi_n= [ [((n X (P-p0))*iit_inv0) X (P-p0)] + 1/m0 + [((n X (P-p1))*iit_inv1) X (P-p1)] + 1/m1 ] ° n
vpi_t= [ [((t X (P-p0))*iit_inv0) X (P-p0)] + 1/m0 + [((t X (P-p1))*iit_inv1) X (P-p1)] + 1/m1 ] ° t
where
iit_inv: inverse moment of inertia tensor
m: mass
6) find the required impulsed we need to apply along n & t
reqI_n = dV_C.x / vpi_n
reqI_t = dV_C.y / vpi_t
7) In the last stage I do some extra fudgy math/physics for dynamic friction.
if(reqI_t > reqI_n*µ)
then reqI_t = reqI_n*µ
else if(reqI_t < -reqI_n*µ)
then reqI_t = -reqI_n*µ
where
µ: friction coefficient
The problem I have with rolling balls
When a ball is rolling over a flat surface, it's Vr_C.y seems to be very close to zero, causing no visible friction to act on the contactpoint.
where
Vr_C.y = (v+(w X (P-p)) ° t
It seems like the v (linear velocity) component and the (w X (P-p) component (linear velocity at P, due to rotation)
cancel each other out.
Have I gone wrong somewhere in my formulas?
How can this be explained?
Thanks for any help.
Last edited: