Reputation: 183
I played around with the JTS Topology Suite which looks quite nice.
However, I couldn't manage to resolve the collision between two Geometry instances. I would like to perform a wall sliding between Geometry A and B (see screenshot below).
I tried to implement the solution posted in this comment (Solution 2): https://gamedev.stackexchange.com/questions/104099/how-to-go-about-an-intermediate-collision-resolution-system/104105#104105
However, I couldn't manage to calculate a raycast or even calculate the normal of B's border vector which A collides.
Would someone give me a starting point of how to implement a wall sliding using JTS?
EDIT: The Geometry class provides to methods which might help me "intersects" and "intersection". "intersects" returns true if the argument geometry interects this geometry. "intersection" returns a Geometry representing the point-set which is common to both Geometries. Maybe I could use "intersection" to find the first collision point.
Has anyone done this with the JTS? Maybe the suite already provides algorithm to perform this task.
Thanks in advance
Upvotes: 1
Views: 821
Reputation: 88757
Raycasting means you define a starting point as well as a direction and calculate in infinite length vector (ray). Then you calculate where that ray would hit an object.
In your case the ray direction would be your motion vector, the starting point would depend on the shape of your geometry/bounding shape. In case of a bounding box you could cast multiple rays from each of the corners and check which hits the obstacle first. Of course this wouldn't work correctly if the box would hit the obstacle's corner etc. However this might provide a starting point. Note that efficient and correct collision detection is a really complex topic.
As for your second question: IIRC the collision normal is the average of the motion vector and projection of the motion vector onto the collision surface. The weight of each vector would depend on movement speed and surface properties, e.g. bounciness. Again quite a complex topic and my memory might trick me here (collision normal might as well just be the normal of the collision surface at the point of impact)
Let me try to illustrate the second point with some ascii diagram:
O - moving object
\ - motion vector
\
\ / - collision normal
\ /
___\/__.___________ - collision surface ("average" of motion vector and vector between impact point and the "dot" projected onto the surface)
\ |
\ | - project motion vector from "inside" onto the collision surface (up in this case)
\|
Note that's right off my head which might trick me atm, I'll look up some tutorials/descriptions if I have time.
Some link(s) that might help you get started:
Upvotes: 1