Author Topic: math collision problem.  (Read 510 times)

kay so I'm making a game and you can drag objects around. when you drag an object two variables are stored: the position of the object at the end of the last frame (lastPos) and the current position at the start of this frame (currPos). with these two variables I have a vector for which the object is traveling during the current frame.

my collision works like this: objects have a collider, each with a set number of corners. the object you're dragging fires the aforementioned vector from each corner along the same direction to detect any collision. when it finds one, it gets the distance between that specific collision corner and the point hit, and updates the movement vector so that its distance is now shortened to the collision vector, meaning that the object will be unable to move past the collision point.

the problem: upon this frame, the two objects are now touching each other and are side by side. the problem is that when I try to drag the object again, it will no longer move, because the corners that are colliding with the object are permanently stuck inside that object's collision. I cannot cast a new movement vector going away from the object because the start point of the vector is 'inside' a collider already. I've tried adding a small amount of easing where the start of the vector is actually like 0.01% ahead of where its supposed to be, but that just results in objects getting stuck inside each other when I drag them too fast.



the green Xs are points of collision detected. the magenta lines are the vectors that scan for collisions. what I want is for the fourth(bottom right) scenario to not happen. I want the box to move freely from its original collision away from it without colliding directly at the source of the vector

in this problem, I don't have any low-level access to the collision routines or the colliders, they are handled automatically by the game engine (unity). there is no built in friction fields I can use, i'd have to make my own using vector math. so I need to figure out a solution that involves modifying the starting vector in some way. thing is idk how. someone with knowledge on this stuff please help me or pass this problem along to your smart friends
« Last Edit: February 19, 2019, 12:05:47 PM by PhantOS »

i think the solution is for you to not be gay and for me to be actually helpful


shorten the vectors
This is the actual shortest answer I've ever seen and it actually should work

that wont fix the issue cause the problem is the vectors start "within" the collision shape and thus instantly collide with it, regardless of vector length.

i talked to phanto over discord and suggested a projection-based system where instead of using vectors, it projects the shape in its "new" position then corrects it by snapping it to the nearest valid location, if it overlaps another collision shape. depending on how complicated your shapes are, this may or may not be easy/simple/efficient/possible to implement, but for simple convex shapes it should be fine

shorten the vectors
I've tried adding a small amount of easing where the start of the vector is actually like 0.01% ahead of where its supposed to be, but that just results in objects getting stuck inside each other when I drag them too fast.