I play a game on wheels, and I can not get my sphere-mesh collision code to work properly.
Currently, what I have for the main loop (regarding the collision) is:
Calculate the player's acceleration based on inputs Tightening speed to avoid clipping Add speed to the position Add acceleration to speed For each solid object: Check the collision for this object and solve it (the procedure is as follows) If there were collisions: Normalize the accumulated normal vector (explained below) Slow the ball to account for friction
I've tried two main methods to solve collisions, each with its own problems.
The first method:
For each triangle: In case of collision: Correction of the player's speed along the normal depending on the distance Accumulate the normal for friction calculations later If the speed perpendicular to the surface is greater than the threshold: Bounce off the ball off surface with damping factor Otherwise, if you move to the surface instead of moving away Clear perpendicular speed
The problem with this method is that when I hit a wall, the player will start bouncing erratically. The collision that I use to test this looks like this (player at scale):
The second method is similar to the first one:
Set the collision distance accumulator to an arbitrarily high value Set the triangle's index to -1 (to indicate that there are no collisions) For each triangle: In case of collision: Calculate the collision distance If this distance is less than the value of the accumulator: Set the triangle index on the current triangle Set the collision distance accumulator on the current distance value If the index is not -1 (there was a collision): Correction of the player's speed along the normal according to the distance in the accumulator Accumulate the normal for friction calculations later If the speed perpendicular to the surface is greater than the threshold: Bounce off the ball off surface with damping factor Otherwise, if you move to the surface rather than to the outside: Clear perpendicular speed
This corrects the problem of stiffness, but I can now move partly on surfaces supposed to be solid.
I do not know where to go at this point. I hope someone here will be able to give an overview of what is going on.
[EDIT] I can add videos if it helps somebody.
[EDIT 2] Here is a link of a video using the first method: