dotnet-ad / Humper

Collision detection for Axis-Aligned-Bounding-Boxes (aka AABB) in C#.
MIT License
104 stars 19 forks source link

Vector2 Math #2

Open implicit-invocation opened 7 years ago

implicit-invocation commented 7 years ago

https://github.com/aloisdeniel/Humper/blob/master/Sources/Humper/Hit.cs#L350

Is the math here correct? origin was modified before calculating thanDistance
I tried to load this TMX and build some walls. But my body always goes through wall#13 and stick to the bottom side of wall#9

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" tiledversion="1.0.1" orientation="orthogonal" renderorder="right-down" width="10" height="10" tilewidth="32" tileheight="32" nextobjectid="14">
 <objectgroup name="Obstacles">
  <object id="7" x="46.6667" y="-6.66667" width="32" height="162.667"/>
  <object id="9" x="-6" y="11.3333" width="250" height="32"/>
  <object id="10" x="5.33333" y="54.6667" width="62.6667" height="63.3333"/>
  <object id="13" x="120" y="110.667" width="138" height="43.3333"/>
 </objectgroup>
</map>
map = new TmxMap("test.tmx");
world = new World(map.Width, map.Height);
body = world.Create(100, 100, 20, 20);

foreach(var obj in map.ObjectGroups["Obstacles"].Objects) {
  walls.Add(world.Create((float)obj.X, (float)obj.Y, (float)obj.Width, (float)obj.Height));
}