Move sphere out of line segment = stuck

Started by
30 comments, last by NikiTo 3 years, 8 months ago

_WeirdCat_ said:
Just to clarify look at this drawing you made red line is pdst, green line is sphere_radius (scaled radius)

Not sure what you mean, but i guess you want to find the exact time where the sphere hits the vertex?

Then, like NikiTo said above, you can make the vertex a sphere (Minkovski sum) and the sphere a point, and trace a ray along velocity against the vertex sphere.
To extend this approach to a polyhedron, edges become cylinders, and faces can be offset along their normal by sphere radius.

Here is some code i used for ray-sphere intersection (rO,dD = ray origin and direction; sO = sphere origin):

	inline bool IntersectRaySphere (float &t0, float &t1, 
		const vec &rO, const vec &rD, const vec &sO, const float sqRad) 
	{
		vec l = sO - rO; 
		float a = l.Dot(rD); 
		//if (a < 0) return false; 
		float d2 = l.Dot(l) - a * a; 
		if (d2 > sqRad) return false; 
		float b = sqrt(sqRad - d2); 
		t0 = a - b; 
		t1 = a + b;
		return true; 
	}

But notice that this only predicts collisions and helps to prevent penetration, but it does not resolve penetration that already exists (or drifts in with time).

I assume such Minkovski methods are mostly used to implement CCD, while resting contact is handled with resolving intersections. But not sure.

Advertisement

I can reccomend dilation approach only for moving a player around. It could work or help in other scenarios too, but i am not saying it. I can only reccomend it for moving a player around.

In 3D, for a tall player character, it could require a dedicated approach -

Could require a cilinder.

This topic is closed to new replies.

Advertisement