I am trying my hand at game physics.
I understand that the basic way to pull back a sphere when it collided is to negate the penetration distance:
// If collided... // `distance`: distance form triangle face; a negative number // `normal` : triangle face, in vec3 // `position`: sphere center, in vec3 position.x -= normal.x * distance; position.y -= normal.y * distance; position.z -= normal.z * distance;
But I don't want to change y coordinate, while the player is on the ground like this (side view):
How can I calculate the expected translation?
I have these values:
- penetration distance, as a negative number (shown in blue)
- triangle face normal, as a
vec3(shown in red)
- triangle vertices, as 3
- sphere radius, as a number
- sphere center, as a
Answers in any programing language are welcome!
updated Jul 17, 2014
I found a hint. It's difficult to explain, I will attach 2 more figures.
It seems, dashed lines in following figures are the translation value what I need, I guess.
and in another case