Here is what happens when approaching corners at certain angles.
Its note worthy that the same thing happens all over bar the corners if the triangle is defined clockwise.
In most cases its just sucked into the triangle and spat back out. But at certain angles the shape may be pulled straight through to the other side.
If the triangle is defined clockwise the AABB will get sucked in and spasm about until (with user input) the AABB is pushed out of the triangle.
[attachment=7059:Err.png]
Now I have no clue whats going on but if I try to use this a completely unrelated method doesn't function?!?
The draw function.
First I tried drawing the shapes after the colour was changed in reaction to this method in the update method. Neither shapes were drawn?
Next I tried drawing the shapes in reaction to this method in the draw method, if iscolliding true, draw blue else draw black. only shape B was drawn.
If I do not run this method, both shapes draw perfectly.
you're not projecting onto the axis properly and not subtracting the half-widths projection lengths from the center projecting lengths either to determine intersection.
projection vector of vector A onto vector B is (A dot B) / (B length Squared) * B. use this against the B center to A center vector, and the half-width/height vectors of both to get their projection vector, so you can get their projection lengths. If the sum of the half-width/height lengths - center length > 0, there is a possible collision on thix axis, if its < 0, there is no collision at all, since from this axis they are not colliding (which is a return condition). Basically you're testing for overlap in the projections. if the centers are far enough apart, there is no overlap, so subtracing the center projection length is less than zero. If the centers are too close, their center projection length is smaller than their combined half-width/height projection lengths and therefore when the center length is subtracted it will be positive, indicating that they are overlaping, meaning from this axis an overlap is possible.
I have a journal about an SAT implementation for tilemaps that may offer some guidance.
Actually projection onto a axis providing the axis is normalized is
Projection = Dot Product of Vector and Axis
I've already got that to work fine as well as get it to resolve collisions fairly accurately, though when trying to test my revised version after making my own Vector class to allow looping (the one above) I ran into the weird not drawing problem,
which is actually my main concern.
all fixxed! implementation is working completely!
for anyone in need of help on this here is my Shape class, it should be easy enough to read.
import java.awt.Graphics;
public class Shape {
public Vector2 pos;
public Vector2[] v;
public Shape(Vector2 Pos, Vector2[] Vecs)
{
pos = Pos;
v = Vecs;
}
public static boolean isColliding(Shape a, Shape b)
{
Shape s1, s2;
Vector2 temp1, temp2;
s1 = new Shape(a.pos, a.v.clone());
s2 = new Shape(b.pos, b.v.clone());
Vector2[] Axis = new Vector2[s1.v.length + s2.v.length];
for (int i = 0; i < s1.v.length; i++)
{
Axis = Vector2.Normalize(Vector2.Perp(Vector2.Sub(s1.v, s1.v[i == s1.v.length-1 ? 0 : i+1])));
}
for (int i = 0; i < s2.v.length; i++)
{
Axis[i + s1.v.length] = Vector2.Normalize(Vector2.Perp(Vector2.Sub(s2.v, s2.v[i == s2.v.length-1 ? 0 : i+1])));
}
for (int i = 0; i < Axis.length; i++)
{
temp1 = s1.Project(Axis);
temp2 = s2.Project(Axis);