Fix wallmount constrution ghost rotation check. (#6272)
This commit is contained in:
@@ -21,14 +21,17 @@ namespace Content.Shared.Construction.Conditions
|
|||||||
var entManager = IoCManager.Resolve<IEntityManager>();
|
var entManager = IoCManager.Resolve<IEntityManager>();
|
||||||
|
|
||||||
// get blueprint and user position
|
// get blueprint and user position
|
||||||
var userWorldPosition = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(user).WorldPosition;
|
var userWorldPosition = entManager.GetComponent<TransformComponent>(user).WorldPosition;
|
||||||
var objWorldPosition = location.ToMap(entManager).Position;
|
var objWorldPosition = location.ToMap(entManager).Position;
|
||||||
|
|
||||||
// find direction from user to blueprint
|
// find direction from user to blueprint
|
||||||
var userToObject = (objWorldPosition - userWorldPosition);
|
var userToObject = (objWorldPosition - userWorldPosition);
|
||||||
|
// get direction of the grid being placed on as an offset.
|
||||||
|
var gridRotation = entManager.GetComponent<TransformComponent>(location.EntityId).WorldRotation;
|
||||||
|
var directionWithOffset = gridRotation.RotateVec(direction.ToVec());
|
||||||
|
|
||||||
// dot product will be positive if user direction and blueprint are co-directed
|
// dot product will be positive if user direction and blueprint are co-directed
|
||||||
var dotProd = Vector2.Dot(direction.ToVec(), userToObject);
|
var dotProd = Vector2.Dot(directionWithOffset.Normalized, userToObject.Normalized);
|
||||||
if (dotProd > 0)
|
if (dotProd > 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -36,7 +39,7 @@ namespace Content.Shared.Construction.Conditions
|
|||||||
var physics = EntitySystem.Get<SharedPhysicsSystem>();
|
var physics = EntitySystem.Get<SharedPhysicsSystem>();
|
||||||
var rUserToObj = new CollisionRay(userWorldPosition, userToObject.Normalized, (int) CollisionGroup.Impassable);
|
var rUserToObj = new CollisionRay(userWorldPosition, userToObject.Normalized, (int) CollisionGroup.Impassable);
|
||||||
var length = userToObject.Length;
|
var length = userToObject.Length;
|
||||||
var userToObjRaycastResults = physics.IntersectRayWithPredicate(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(user).MapID, rUserToObj, maxLength: length,
|
var userToObjRaycastResults = physics.IntersectRayWithPredicate(entManager.GetComponent<TransformComponent>(user).MapID, rUserToObj, maxLength: length,
|
||||||
predicate: (e) => !e.HasTag("Wall"));
|
predicate: (e) => !e.HasTag("Wall"));
|
||||||
if (!userToObjRaycastResults.Any())
|
if (!userToObjRaycastResults.Any())
|
||||||
return false;
|
return false;
|
||||||
@@ -45,8 +48,8 @@ namespace Content.Shared.Construction.Conditions
|
|||||||
var targetWall = userToObjRaycastResults.First().HitEntity;
|
var targetWall = userToObjRaycastResults.First().HitEntity;
|
||||||
|
|
||||||
// check that we didn't try to build wallmount that facing another adjacent wall
|
// check that we didn't try to build wallmount that facing another adjacent wall
|
||||||
var rAdjWall = new CollisionRay(objWorldPosition, direction.ToVec(), (int) CollisionGroup.Impassable);
|
var rAdjWall = new CollisionRay(objWorldPosition, directionWithOffset.Normalized, (int) CollisionGroup.Impassable);
|
||||||
var adjWallRaycastResults = physics.IntersectRayWithPredicate(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(user).MapID, rAdjWall, maxLength: 0.5f,
|
var adjWallRaycastResults = physics.IntersectRayWithPredicate(entManager.GetComponent<TransformComponent>(user).MapID, rAdjWall, maxLength: 0.5f,
|
||||||
predicate: (e) => e == targetWall || !e.HasTag("Wall"));
|
predicate: (e) => e == targetWall || !e.HasTag("Wall"));
|
||||||
return !adjWallRaycastResults.Any();
|
return !adjWallRaycastResults.Any();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user