Not logged inOpenClonk Forum
Up Topic Collection+Entry=ControlArea

This board is threaded (i.e. has a tree structure). Please use the Reply button of the specific post you are referring to, not just any random button. If you want to reply to the topic in general, use the Post button near the top and bottom of the page.

Post Reply
In Response to Sven2
You know, it's easy to calculate if (and when) two spheres of known position and velocity collide.

Be x0(t)=p0+v0*t the position of object one; be x1(t)=p1+v1*t the position of object two. The distance of the two is D(t)=||x0(t)-x1(t)||. The minimum distance is at d/dt D(t) = 0. Derive and resolve t (excluding any special cases of zero velocity and such here):

D(t) = sqrt((p0x-p1x+(v0x-v1x)*t )^2 + (p0y-p1y+(v0y-v1y)*t )^2)

d/dt D(t) = 1/sqrt((p0x-p1x+(v0x-v1x)*t )^2 + (p0y-p1y+(v0y-v1y)*t )^2) * (2*(p0x-p1x+(v0x-v1x)*t )*(v0x-v1x) + 2*(p0y-p1y+(v0y-v1y)*t )*(v0y-v1y)) = 0
(p0x-p1x+(v0x-v1x)*t )*(v0x-v1x) + (p0y-p1y+(v0y-v1y)*t )*(v0y-v1y) = 0
(p0x-p1x)*(v0x-v1x) + (p0y-p1y)*(v0y-v1y) = -t * ((v0x-v1x)^2+(v0y-v1y)^2)
t = -((p0x-p1x)*(v0x-v1x) + (p0y-p1y)*(v0y-v1y)) / ((v0x-v1x)^2+(v0y-v1y)^2)

This gives you the time t at which the distance of the two objects is minimal. Clamp t to 0-1 (for the duration of 1 frame) and check if D(t) is smaller than the sum of the two sphere's radius.

(math not double checked, but you should get the point)

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill