If a building and unit are found within the line, target the closer one. (#4646)
This commit is contained in:
@@ -214,10 +214,10 @@ public class Damage{
|
|||||||
*/
|
*/
|
||||||
public static Healthc linecast(Bullet hitter, float x, float y, float angle, float length){
|
public static Healthc linecast(Bullet hitter, float x, float y, float angle, float length){
|
||||||
tr.trns(angle, length);
|
tr.trns(angle, length);
|
||||||
|
|
||||||
|
tmpBuilding = null;
|
||||||
|
|
||||||
if(hitter.type.collidesGround){
|
if(hitter.type.collidesGround){
|
||||||
tmpBuilding = null;
|
|
||||||
|
|
||||||
world.raycastEachWorld(x, y, x + tr.x, y + tr.y, (cx, cy) -> {
|
world.raycastEachWorld(x, y, x + tr.x, y + tr.y, (cx, cy) -> {
|
||||||
Building tile = world.build(cx, cy);
|
Building tile = world.build(cx, cy);
|
||||||
if(tile != null && tile.team != hitter.team){
|
if(tile != null && tile.team != hitter.team){
|
||||||
@@ -226,8 +226,6 @@ public class Damage{
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
if(tmpBuilding != null) return tmpBuilding;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rect.setPosition(x, y).setSize(tr.x, tr.y);
|
rect.setPosition(x, y).setSize(tr.x, tr.y);
|
||||||
@@ -271,6 +269,14 @@ public class Damage{
|
|||||||
|
|
||||||
Units.nearbyEnemies(hitter.team, rect, cons);
|
Units.nearbyEnemies(hitter.team, rect, cons);
|
||||||
|
|
||||||
|
if(tmpBuilding != null && tmpUnit != null){
|
||||||
|
float bDst = Mathf.dst2(x, y, tmpBuilding.getX(), tmpBuilding.getY());
|
||||||
|
float uDst = Mathf.dst2(x, y, tmpUnit.getX(), tmpUnit.getY());
|
||||||
|
if(uDst <= bDst) return tmpUnit;
|
||||||
|
if(bDst > uDst) return tmpBuilding;
|
||||||
|
}else if(tmpBuilding != null && tmpUnit == null){
|
||||||
|
return tmpBuilding;
|
||||||
|
}
|
||||||
return tmpUnit;
|
return tmpUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user