(5bab406f1) Fixed "allowInsideFixture" raycasts not working correctly - checking if the ray is inside the AABB is not enough, we also need to take the shape and rotation of the fixture into account.
This commit is contained in:
@@ -884,6 +884,39 @@ namespace Barotrauma
|
||||
|
||||
AllowedLinks = element.GetAttributeStringArray("allowedlinks", new string[0], convertToLowerInvariant: true).ToList();
|
||||
|
||||
if (sprite == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Item \"" + Name + "\" has no sprite!");
|
||||
#if SERVER
|
||||
sprite = new Sprite("", Vector2.Zero);
|
||||
sprite.SourceRect = new Rectangle(0, 0, 32, 32);
|
||||
#else
|
||||
sprite = new Sprite(TextureLoader.PlaceHolderTexture, null, null)
|
||||
{
|
||||
Origin = TextureLoader.PlaceHolderTexture.Bounds.Size.ToVector2() / 2
|
||||
};
|
||||
#endif
|
||||
size = sprite.size;
|
||||
sprite.EntityID = identifier;
|
||||
}
|
||||
|
||||
if (!category.HasFlag(MapEntityCategory.Legacy) && string.IsNullOrEmpty(identifier))
|
||||
{
|
||||
DebugConsole.ThrowError(
|
||||
"Item prefab \"" + name + "\" has no identifier. All item prefabs have a unique identifier string that's used to differentiate between items during saving and loading.");
|
||||
}
|
||||
if (!string.IsNullOrEmpty(identifier))
|
||||
{
|
||||
MapEntityPrefab existingPrefab = List.Find(e => e.Identifier == identifier);
|
||||
if (existingPrefab != null)
|
||||
{
|
||||
DebugConsole.ThrowError(
|
||||
"Map entity prefabs \"" + name + "\" and \"" + existingPrefab.Name + "\" have the same identifier!");
|
||||
}
|
||||
}
|
||||
|
||||
AllowedLinks = element.GetAttributeStringArray("allowedlinks", new string[0], convertToLowerInvariant: true).ToList();
|
||||
|
||||
List.Add(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -678,17 +678,24 @@ namespace Barotrauma
|
||||
Body closestBody = null;
|
||||
if (allowInsideFixture)
|
||||
{
|
||||
var aabb = new FarseerPhysics.Collision.AABB(rayStart - Vector2.UnitY * 0.001f, rayStart + Vector2.UnitY * 0.001f);
|
||||
var aabb = new FarseerPhysics.Collision.AABB(rayStart - Vector2.One * 0.001f, rayStart + Vector2.One * 0.001f);
|
||||
GameMain.World.QueryAABB((fixture) =>
|
||||
{
|
||||
if (!CheckFixtureCollision(fixture, ignoredBodies, collisionCategory, ignoreSensors, customPredicate)) { return false; }
|
||||
if (!CheckFixtureCollision(fixture, ignoredBodies, collisionCategory, ignoreSensors, customPredicate)) { return true; }
|
||||
|
||||
fixture.Body.GetTransform(out FarseerPhysics.Common.Transform transform);
|
||||
if (!fixture.Shape.TestPoint(ref transform, ref rayStart)) { return true; }
|
||||
|
||||
closestFraction = 0.0f;
|
||||
closestNormal = Vector2.Normalize(rayEnd - rayStart);
|
||||
if (fixture.Body != null) closestBody = fixture.Body;
|
||||
return true;
|
||||
return false;
|
||||
}, ref aabb);
|
||||
if (closestFraction <= 0.0f)
|
||||
{
|
||||
lastPickedPosition = rayStart;
|
||||
lastPickedFraction = closestFraction;
|
||||
lastPickedNormal = closestNormal;
|
||||
return closestBody;
|
||||
}
|
||||
}
|
||||
@@ -740,14 +747,21 @@ namespace Barotrauma
|
||||
|
||||
if (allowInsideFixture)
|
||||
{
|
||||
var aabb = new FarseerPhysics.Collision.AABB(rayStart - Vector2.UnitY * 0.001f, rayStart + Vector2.UnitY * 0.001f);
|
||||
var aabb = new FarseerPhysics.Collision.AABB(rayStart - Vector2.One * 0.001f, rayStart + Vector2.One * 0.001f);
|
||||
GameMain.World.QueryAABB((fixture) =>
|
||||
{
|
||||
if (bodies.Contains(fixture.Body) || fixture.Body == null) { return false; }
|
||||
if (!CheckFixtureCollision(fixture, ignoredBodies, collisionCategory, ignoreSensors, customPredicate)) { return false; }
|
||||
if (bodies.Contains(fixture.Body) || fixture.Body == null) { return true; }
|
||||
if (!CheckFixtureCollision(fixture, ignoredBodies, collisionCategory, ignoreSensors, customPredicate)) { return true; }
|
||||
|
||||
fixture.Body.GetTransform(out FarseerPhysics.Common.Transform transform);
|
||||
if (!fixture.Shape.TestPoint(ref transform, ref rayStart)) { return true; }
|
||||
|
||||
closestFraction = 0.0f;
|
||||
lastPickedPosition = rayStart;
|
||||
lastPickedFraction = 0.0f;
|
||||
lastPickedNormal = Vector2.Normalize(rayEnd - rayStart);
|
||||
bodies.Add(fixture.Body);
|
||||
return true;
|
||||
return false;
|
||||
}, ref aabb);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user