From 40008f44ac52f010770e14985ecb2a7befaae1a1 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 1 Oct 2018 13:28:35 -0400 Subject: [PATCH 1/6] Circle collision initial commit --- core/src/io/anuke/mindustry/core/Control.java | 4 ++-- core/src/io/anuke/mindustry/core/Logic.java | 10 +++++----- .../src/io/anuke/mindustry/core/NetServer.java | 4 ++-- core/src/io/anuke/mindustry/core/World.java | 8 ++++---- .../io/anuke/mindustry/entities/Player.java | 4 ---- core/src/io/anuke/mindustry/entities/Unit.java | 12 ------------ .../src/io/anuke/mindustry/entities/Units.java | 18 +++++++++--------- .../mindustry/entities/units/BaseUnit.java | 1 - .../world/blocks/defense/ForceProjector.java | 4 ++-- 9 files changed, 24 insertions(+), 41 deletions(-) diff --git a/core/src/io/anuke/mindustry/core/Control.java b/core/src/io/anuke/mindustry/core/Control.java index 4b913632a0..801f9f73b9 100644 --- a/core/src/io/anuke/mindustry/core/Control.java +++ b/core/src/io/anuke/mindustry/core/Control.java @@ -24,7 +24,7 @@ import io.anuke.mindustry.type.Recipe; import io.anuke.mindustry.ui.dialogs.FloatingDialog; import io.anuke.ucore.core.*; import io.anuke.ucore.entities.Entities; -import io.anuke.ucore.entities.EntityPhysics; +import io.anuke.ucore.entities.EntityQuery; import io.anuke.ucore.modules.Module; import io.anuke.ucore.util.Atlas; @@ -302,7 +302,7 @@ public class Control extends Module{ @Override public void init(){ - EntityPhysics.initPhysics(); + EntityQuery.init(); Platform.instance.updateRPC(); diff --git a/core/src/io/anuke/mindustry/core/Logic.java b/core/src/io/anuke/mindustry/core/Logic.java index 63bcb58e51..018f46a698 100644 --- a/core/src/io/anuke/mindustry/core/Logic.java +++ b/core/src/io/anuke/mindustry/core/Logic.java @@ -17,7 +17,7 @@ import io.anuke.ucore.core.Events; import io.anuke.ucore.core.Timers; import io.anuke.ucore.entities.Entities; import io.anuke.ucore.entities.EntityGroup; -import io.anuke.ucore.entities.EntityPhysics; +import io.anuke.ucore.entities.EntityQuery; import io.anuke.ucore.modules.Module; import static io.anuke.mindustry.Vars.*; @@ -39,8 +39,8 @@ public class Logic extends Module{ @Override public void init(){ - EntityPhysics.initPhysics(); - EntityPhysics.collisions().setCollider(tilesize, world::solid); + EntityQuery.init(); + EntityQuery.collisions().setCollider(tilesize, world::solid); } public void play(){ @@ -167,11 +167,11 @@ public class Logic extends Module{ for(EntityGroup group : unitGroups){ if(!group.isEmpty()){ - EntityPhysics.collideGroups(bulletGroup, group); + EntityQuery.collideGroups(bulletGroup, group); } } - EntityPhysics.collideGroups(bulletGroup, playerGroup); + EntityQuery.collideGroups(bulletGroup, playerGroup); world.pathfinder().update(); } diff --git a/core/src/io/anuke/mindustry/core/NetServer.java b/core/src/io/anuke/mindustry/core/NetServer.java index 25fd2511d5..b4264fd8f2 100644 --- a/core/src/io/anuke/mindustry/core/NetServer.java +++ b/core/src/io/anuke/mindustry/core/NetServer.java @@ -27,7 +27,7 @@ import io.anuke.mindustry.world.Tile; import io.anuke.ucore.core.Timers; import io.anuke.ucore.entities.Entities; import io.anuke.ucore.entities.EntityGroup; -import io.anuke.ucore.entities.EntityPhysics; +import io.anuke.ucore.entities.EntityQuery; import io.anuke.ucore.entities.trait.Entity; import io.anuke.ucore.io.ByteBufferOutput; import io.anuke.ucore.io.CountableByteArrayOutputStream; @@ -508,7 +508,7 @@ public class NetServer extends Module{ returnArray.clear(); if(represent.isClipped()){ - EntityPhysics.getNearby(group, viewport, entity -> { + EntityQuery.getNearby(group, viewport, entity -> { if(((SyncTrait) entity).isSyncing() && viewport.contains(entity.getX(), entity.getY())){ returnArray.add(entity); } diff --git a/core/src/io/anuke/mindustry/core/World.java b/core/src/io/anuke/mindustry/core/World.java index fe0906b891..c2d09dc1e5 100644 --- a/core/src/io/anuke/mindustry/core/World.java +++ b/core/src/io/anuke/mindustry/core/World.java @@ -18,7 +18,7 @@ import io.anuke.mindustry.maps.generation.WorldGenerator; import io.anuke.mindustry.world.blocks.OreBlock; import io.anuke.ucore.core.Events; import io.anuke.ucore.core.Timers; -import io.anuke.ucore.entities.EntityPhysics; +import io.anuke.ucore.entities.EntityQuery; import io.anuke.ucore.modules.Module; import io.anuke.ucore.util.Log; import io.anuke.ucore.util.Mathf; @@ -222,7 +222,7 @@ public class World extends Module{ } } - EntityPhysics.resizeTree(0, 0, tiles.length * tilesize, tiles[0].length * tilesize); + EntityQuery.resizeTree(0, 0, tiles.length * tilesize, tiles[0].length * tilesize); generating = false; Events.fire(new WorldLoadEvent()); @@ -251,7 +251,7 @@ public class World extends Module{ Map map = new Map("Sector " + sector.x + ", " + sector.y, new MapMeta(0, new ObjectMap<>(), width, height, null), true, () -> null); setMap(map); - EntityPhysics.resizeTree(0, 0, width * tilesize, height * tilesize); + EntityQuery.resizeTree(0, 0, width * tilesize, height * tilesize); generator.generateMap(tiles, sector); @@ -267,7 +267,7 @@ public class World extends Module{ createTiles(width, height); - EntityPhysics.resizeTree(0, 0, width * tilesize, height * tilesize); + EntityQuery.resizeTree(0, 0, width * tilesize, height * tilesize); try{ generator.loadTileData(tiles, MapIO.readTileData(map, true), map.meta.hasOreGen(), 0); diff --git a/core/src/io/anuke/mindustry/entities/Player.java b/core/src/io/anuke/mindustry/entities/Player.java index d7eb92ae78..2ae4e48ac8 100644 --- a/core/src/io/anuke/mindustry/entities/Player.java +++ b/core/src/io/anuke/mindustry/entities/Player.java @@ -487,10 +487,6 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra updateMech(); } - if(isLocal){ - avoidOthers(8f); - } - updateBuilding(this); x = Mathf.clamp(x, 0, world.width() * tilesize); diff --git a/core/src/io/anuke/mindustry/entities/Unit.java b/core/src/io/anuke/mindustry/entities/Unit.java index 3120fdfda6..4ae18c14ae 100644 --- a/core/src/io/anuke/mindustry/entities/Unit.java +++ b/core/src/io/anuke/mindustry/entities/Unit.java @@ -15,7 +15,6 @@ import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.blocks.Floor; import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Timers; -import io.anuke.ucore.entities.EntityPhysics; import io.anuke.ucore.entities.impl.DestructibleEntity; import io.anuke.ucore.entities.trait.DamageTrait; import io.anuke.ucore.entities.trait.DrawTrait; @@ -193,17 +192,6 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ return tile == null ? (Floor) Blocks.air : tile.floor(); } - public void avoidOthers(float avoidRange){ - - EntityPhysics.getNearby(getGroup(), x, y, avoidRange * 2f, t -> { - if(t == this || (t instanceof Unit && (((Unit) t).isDead() || (((Unit) t).isFlying() != isFlying()) || ((Unit) t).getCarrier() == this) || getCarrier() == t)) - return; - float dst = distanceTo(t); - if(dst > avoidRange) return; - velocity.add(moveVector.set(x, y).sub(t.getX(), t.getY()).setLength(1f * (1f - (dst / avoidRange)) / getMass())); - }); - } - /**Updates velocity and status effects.*/ public void updateVelocityStatus(float drag, float maxVelocity){ Floor floor = getFloorOn(); diff --git a/core/src/io/anuke/mindustry/entities/Units.java b/core/src/io/anuke/mindustry/entities/Units.java index 5bcb881a14..a777ddee76 100644 --- a/core/src/io/anuke/mindustry/entities/Units.java +++ b/core/src/io/anuke/mindustry/entities/Units.java @@ -8,7 +8,7 @@ import io.anuke.mindustry.game.Team; import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Tile; import io.anuke.ucore.entities.EntityGroup; -import io.anuke.ucore.entities.EntityPhysics; +import io.anuke.ucore.entities.EntityQuery; import io.anuke.ucore.function.Consumer; import io.anuke.ucore.function.Predicate; import io.anuke.ucore.util.EnumSet; @@ -213,11 +213,11 @@ public class Units{ EntityGroup group = unitGroups[team.ordinal()]; if(!group.isEmpty()){ - EntityPhysics.getNearby(group, rect, entity -> cons.accept((Unit) entity)); + EntityQuery.getNearby(group, rect, entity -> cons.accept((Unit) entity)); } //now check all players - EntityPhysics.getNearby(playerGroup, rect, player -> { + EntityQuery.getNearby(playerGroup, rect, player -> { if(((Unit) player).team == team) cons.accept((Unit) player); }); } @@ -230,7 +230,7 @@ public class Units{ EntityGroup group = unitGroups[team.ordinal()]; if(!group.isEmpty()){ - EntityPhysics.getNearby(group, rect, entity -> { + EntityQuery.getNearby(group, rect, entity -> { if(entity.distanceTo(x, y) <= radius){ cons.accept((Unit) entity); } @@ -238,7 +238,7 @@ public class Units{ } //now check all players - EntityPhysics.getNearby(playerGroup, rect, player -> { + EntityQuery.getNearby(playerGroup, rect, player -> { if(((Unit) player).team == team && player.distanceTo(x, y) <= radius){ cons.accept((Unit) player); } @@ -253,12 +253,12 @@ public class Units{ for(Team team : Team.all){ EntityGroup group = unitGroups[team.ordinal()]; if(!group.isEmpty()){ - EntityPhysics.getNearby(group, rect, entity -> cons.accept((Unit) entity)); + EntityQuery.getNearby(group, rect, entity -> cons.accept((Unit) entity)); } } //now check all enemy players - EntityPhysics.getNearby(playerGroup, rect, player -> cons.accept((Unit) player)); + EntityQuery.getNearby(playerGroup, rect, player -> cons.accept((Unit) player)); } /** @@ -270,12 +270,12 @@ public class Units{ for(Team other : targets){ EntityGroup group = unitGroups[other.ordinal()]; if(!group.isEmpty()){ - EntityPhysics.getNearby(group, rect, entity -> cons.accept((Unit) entity)); + EntityQuery.getNearby(group, rect, entity -> cons.accept((Unit) entity)); } } //now check all enemy players - EntityPhysics.getNearby(playerGroup, rect, player -> { + EntityQuery.getNearby(playerGroup, rect, player -> { if(targets.contains(((Player) player).team)){ cons.accept((Unit) player); } diff --git a/core/src/io/anuke/mindustry/entities/units/BaseUnit.java b/core/src/io/anuke/mindustry/entities/units/BaseUnit.java index 78035af666..15b111772b 100644 --- a/core/src/io/anuke/mindustry/entities/units/BaseUnit.java +++ b/core/src/io/anuke/mindustry/entities/units/BaseUnit.java @@ -306,7 +306,6 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{ } if(!Net.client()){ - avoidOthers(4f + type.hitsize); if(spawner != -1 && (world.tile(spawner) == null || world.tile(spawner).entity == null)){ damage(health); diff --git a/core/src/io/anuke/mindustry/world/blocks/defense/ForceProjector.java b/core/src/io/anuke/mindustry/world/blocks/defense/ForceProjector.java index 420ba46a93..aaf4acee17 100644 --- a/core/src/io/anuke/mindustry/world/blocks/defense/ForceProjector.java +++ b/core/src/io/anuke/mindustry/world/blocks/defense/ForceProjector.java @@ -16,7 +16,7 @@ import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Graphics; import io.anuke.ucore.core.Timers; import io.anuke.ucore.entities.EntityGroup; -import io.anuke.ucore.entities.EntityPhysics; +import io.anuke.ucore.entities.EntityQuery; import io.anuke.ucore.entities.impl.BaseEntity; import io.anuke.ucore.entities.trait.DrawTrait; import io.anuke.ucore.graphics.Draw; @@ -127,7 +127,7 @@ public class ForceProjector extends Block { float realRadius = realRadius(entity); if(!entity.broken){ - EntityPhysics.getNearby(bulletGroup, tile.drawx(), tile.drawy(), realRadius*2f, bullet -> { + EntityQuery.getNearby(bulletGroup, tile.drawx(), tile.drawy(), realRadius*2f, bullet -> { AbsorbTrait trait = (AbsorbTrait)bullet; if(trait.canBeAbsorbed() && trait.getTeam() != tile.getTeam() && isInsideHexagon(trait.getX(), trait.getY(), realRadius * 2f, tile.drawx(), tile.drawy())){ trait.absorb(); From f175bf2c821363e4cbd8c9971141b0308a54aa7e Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 1 Oct 2018 22:49:53 -0400 Subject: [PATCH 2/6] circles were a mistake --- .../io/anuke/mindustry/content/UnitTypes.java | 4 +- core/src/io/anuke/mindustry/core/Control.java | 2 +- core/src/io/anuke/mindustry/core/Logic.java | 10 ++++- .../src/io/anuke/mindustry/core/Renderer.java | 42 +------------------ .../io/anuke/mindustry/entities/Player.java | 40 ++++++++++-------- .../src/io/anuke/mindustry/entities/Unit.java | 27 +++--------- .../mindustry/entities/bullet/Bullet.java | 11 +---- .../mindustry/entities/effect/Lightning.java | 2 + .../entities/traits/TargetTrait.java | 13 +----- .../mindustry/entities/units/BaseUnit.java | 7 +++- .../mindustry/entities/units/GroundUnit.java | 2 +- .../world/blocks/defense/DeflectorWall.java | 4 +- 12 files changed, 57 insertions(+), 107 deletions(-) diff --git a/core/src/io/anuke/mindustry/content/UnitTypes.java b/core/src/io/anuke/mindustry/content/UnitTypes.java index 99575981f7..6bbfca54db 100644 --- a/core/src/io/anuke/mindustry/content/UnitTypes.java +++ b/core/src/io/anuke/mindustry/content/UnitTypes.java @@ -67,6 +67,7 @@ public class UnitTypes implements ContentList{ maxVelocity = 0.8f; speed = 0.15f; drag = 0.4f; + mass = 4f; range = 10f; rotatespeed = 0.06f; weaponOffsetX = 1; @@ -97,7 +98,8 @@ public class UnitTypes implements ContentList{ revenant = new UnitType("revenant", Revenant.class, Revenant::new){{ health = 250; mass = 4f; - speed = 0.14f*mass; + hitsize = 12f; + speed = 0.14f; maxVelocity = 1.4f; drag = 0.01f; isFlying = true; diff --git a/core/src/io/anuke/mindustry/core/Control.java b/core/src/io/anuke/mindustry/core/Control.java index 801f9f73b9..7fc27445d0 100644 --- a/core/src/io/anuke/mindustry/core/Control.java +++ b/core/src/io/anuke/mindustry/core/Control.java @@ -10,9 +10,9 @@ import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.game.Content; -import io.anuke.mindustry.game.Unlocks; import io.anuke.mindustry.game.EventType.*; import io.anuke.mindustry.game.Saves; +import io.anuke.mindustry.game.Unlocks; import io.anuke.mindustry.input.DefaultKeybinds; import io.anuke.mindustry.input.DesktopInput; import io.anuke.mindustry.input.InputHandler; diff --git a/core/src/io/anuke/mindustry/core/Logic.java b/core/src/io/anuke/mindustry/core/Logic.java index 018f46a698..355e30987d 100644 --- a/core/src/io/anuke/mindustry/core/Logic.java +++ b/core/src/io/anuke/mindustry/core/Logic.java @@ -166,8 +166,14 @@ public class Logic extends Module{ } for(EntityGroup group : unitGroups){ - if(!group.isEmpty()){ - EntityQuery.collideGroups(bulletGroup, group); + if(group.isEmpty()) continue; + + EntityQuery.collideGroups(bulletGroup, group); + EntityQuery.collideGroups(group, playerGroup); + + for(EntityGroup other : unitGroups){ + if(other == group || other.isEmpty()) continue; + EntityQuery.collideGroups(group, other); } } diff --git a/core/src/io/anuke/mindustry/core/Renderer.java b/core/src/io/anuke/mindustry/core/Renderer.java index beeccfc38c..dc9b79a214 100644 --- a/core/src/io/anuke/mindustry/core/Renderer.java +++ b/core/src/io/anuke/mindustry/core/Renderer.java @@ -8,7 +8,6 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.ObjectIntMap; -import com.badlogic.gdx.utils.TimeUtils; import io.anuke.mindustry.content.fx.Fx; import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.entities.Player; @@ -31,7 +30,6 @@ import io.anuke.ucore.entities.EntityGroup; import io.anuke.ucore.entities.impl.EffectEntity; import io.anuke.ucore.entities.trait.DrawTrait; import io.anuke.ucore.entities.trait.Entity; -import io.anuke.ucore.entities.trait.SolidTrait; import io.anuke.ucore.function.Consumer; import io.anuke.ucore.function.Predicate; import io.anuke.ucore.graphics.Draw; @@ -340,45 +338,7 @@ public class Renderer extends RendererModule{ } public void drawAndInterpolate(EntityGroup group, Predicate toDraw, Consumer drawer){ - EntityDraw.drawWith(group, toDraw, t -> { - float lastx = t.getX(), lasty = t.getY(), lastrot = 0f; - - if(threads.doInterpolate() && threads.isEnabled() && t instanceof SolidTrait){ - SolidTrait s = (SolidTrait) t; - - lastrot = s.getRotation(); - - if(s.lastUpdated() != 0){ - float timeSinceUpdate = TimeUtils.timeSinceMillis(s.lastUpdated()); - float alpha = Math.min(timeSinceUpdate / s.updateSpacing(), 1f); - - tmpVector1.set(s.lastPosition().x, s.lastPosition().y) - .lerp(tmpVector2.set(lastx, lasty), alpha); - s.setRotation(Mathf.slerp(s.lastPosition().z, lastrot, alpha)); - - s.setX(tmpVector1.x); - s.setY(tmpVector1.y); - } - } - - //TODO extremely hacky - if(t instanceof Player && ((Player) t).getCarry() != null && ((Player) t).getCarry() instanceof Player && ((Player) ((Player) t).getCarry()).isLocal){ - ((Player) t).x = ((Player) t).getCarry().getX(); - ((Player) t).y = ((Player) t).getCarry().getY(); - } - - drawer.accept(t); - - t.setX(lastx); - t.setY(lasty); - - if(threads.doInterpolate() && threads.isEnabled()){ - - if(t instanceof SolidTrait){ - ((SolidTrait) t).setRotation(lastrot); - } - } - }); + EntityDraw.drawWith(group, toDraw, drawer); } @Override diff --git a/core/src/io/anuke/mindustry/entities/Player.java b/core/src/io/anuke/mindustry/entities/Player.java index 2ae4e48ac8..0ce1564854 100644 --- a/core/src/io/anuke/mindustry/entities/Player.java +++ b/core/src/io/anuke/mindustry/entities/Player.java @@ -232,6 +232,21 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra this.y = y; } + @Override + public float getMaxVelocity(){ + return mech.maxSpeed; + } + + @Override + public Queue getPlaceQueue(){ + return placeQueue; + } + + @Override + public String toString(){ + return "Player{" + id + ", mech=" + mech.name + ", local=" + isLocal + ", " + x + ", " + y + "}\n"; + } + @Override public void removed(){ dropCarryLocal(); @@ -440,10 +455,11 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra hitTime -= Timers.delta(); if(Float.isNaN(x) || Float.isNaN(y)){ - TileEntity core = getClosestCore(); - if(core != null){ - set(core.x, core.y); - } + //throw new RuntimeException("NaN found!"); + velocity.set(0f, 0f); + x = 0; + y = 0; + setDead(true); } if(isDead()){ @@ -465,7 +481,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra interpolate(); updateBuilding(this); //building happens even with non-locals status.update(this); //status effect updating also happens with non locals for effect purposes - updateVelocityStatus(mech.drag, mech.maxSpeed); //velocity too, for visual purposes + updateVelocityStatus(); //velocity too, for visual purposes if(getCarrier() != null){ x = getCarrier().getX(); @@ -570,7 +586,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra velocity.add(movement); } float prex = x, prey = y; - updateVelocityStatus(mech.drag, mech.maxSpeed); + updateVelocityStatus(); moved = distanceTo(prex, prey) > 0.01f; }else{ velocity.setZero(); @@ -644,7 +660,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra rotation = Mathf.slerpDelta(rotation, velocity.angle(), velocity.len() / 10f); } - updateVelocityStatus(mech.drag, mech.maxSpeed); + updateVelocityStatus(); //hovering effect x += Mathf.sin(Timers.time() + id * 999, 25f, 0.08f); @@ -734,16 +750,6 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra this.dead = true; } - @Override - public Queue getPlaceQueue(){ - return placeQueue; - } - - @Override - public String toString(){ - return "Player{" + id + ", mech=" + mech.name + ", local=" + isLocal + ", " + x + ", " + y + "}\n"; - } - //endregion //region read and write methods diff --git a/core/src/io/anuke/mindustry/entities/Unit.java b/core/src/io/anuke/mindustry/entities/Unit.java index 4ae18c14ae..cdfd18c8de 100644 --- a/core/src/io/anuke/mindustry/entities/Unit.java +++ b/core/src/io/anuke/mindustry/entities/Unit.java @@ -16,14 +16,12 @@ import io.anuke.mindustry.world.blocks.Floor; import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Timers; import io.anuke.ucore.entities.impl.DestructibleEntity; -import io.anuke.ucore.entities.trait.DamageTrait; import io.anuke.ucore.entities.trait.DrawTrait; import io.anuke.ucore.entities.trait.SolidTrait; import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.graphics.Fill; import io.anuke.ucore.util.Geometry; import io.anuke.ucore.util.Mathf; -import io.anuke.ucore.util.Translator; import java.io.DataInput; import java.io.DataOutput; @@ -39,7 +37,6 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ public static final float velocityPercision = 8f; /**Maximum absolute value of a velocity vector component.*/ public static final float maxAbsVelocity = 127f / velocityPercision; - private static final Vector2 moveVector = new Vector2(); public UnitInventory inventory = new UnitInventory(this); public float rotation; @@ -50,7 +47,6 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ protected Team team = Team.blue; protected CarryTrait carrier; - protected Vector2 velocity = new Translator(0f, 0.0001f); protected float drownTime; @Override @@ -58,16 +54,6 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ return inventory; } - @Override - public float getRotation(){ - return rotation; - } - - @Override - public void setRotation(float rotation){ - this.rotation = rotation; - } - @Override public CarryTrait getCarrier(){ return carrier; @@ -108,8 +94,8 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ @Override public boolean collides(SolidTrait other){ - return other instanceof DamageTrait && other - instanceof TeamTrait && state.teams.areEnemies((((TeamTrait) other).getTeam()), team) && !isDead(); + return true;//other instanceof DamageTrait && other + // instanceof TeamTrait && state.teams.areEnemies((((TeamTrait) other).getTeam()), team) && !isDead(); } @Override @@ -193,10 +179,9 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ } /**Updates velocity and status effects.*/ - public void updateVelocityStatus(float drag, float maxVelocity){ + public void updateVelocityStatus(){ Floor floor = getFloorOn(); - if(isCarried()){ //carried units do not take into account velocity normally set(carrier.getX(), carrier.getY()); velocity.set(carrier.getVelocity()); @@ -207,7 +192,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ status.update(this); - velocity.limit(maxVelocity).scl(status.getSpeedMultiplier()); + velocity.limit(getMaxVelocity()).scl(status.getSpeedMultiplier()); if(isFlying()){ x += velocity.x / getMass() * Timers.delta(); @@ -255,12 +240,12 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ } float px = x, py = y; - move(velocity.x / getMass() * floor.speedMultiplier * Timers.delta(), velocity.y / getMass() * floor.speedMultiplier * Timers.delta()); + move(velocity.x * floor.speedMultiplier * Timers.delta(), velocity.y * floor.speedMultiplier * Timers.delta()); if(Math.abs(px - x) <= 0.0001f) velocity.x = 0f; if(Math.abs(py - y) <= 0.0001f) velocity.y = 0f; } - velocity.scl(Mathf.clamp(1f - drag * (isFlying() ? 1f : floor.dragMultiplier) * Timers.delta())); + velocity.scl(Mathf.clamp(1f - getDrag() * (isFlying() ? 1f : floor.dragMultiplier) * Timers.delta())); } public void applyEffect(StatusEffect effect, float intensity){ diff --git a/core/src/io/anuke/mindustry/entities/bullet/Bullet.java b/core/src/io/anuke/mindustry/entities/bullet/Bullet.java index 926556e473..4910df3a40 100644 --- a/core/src/io/anuke/mindustry/entities/bullet/Bullet.java +++ b/core/src/io/anuke/mindustry/entities/bullet/Bullet.java @@ -1,7 +1,6 @@ package io.anuke.mindustry.entities.bullet; import com.badlogic.gdx.math.Vector2; -import com.badlogic.gdx.utils.TimeUtils; import io.anuke.annotations.Annotations.Loc; import io.anuke.annotations.Annotations.Remote; import io.anuke.mindustry.entities.Unit; @@ -69,15 +68,9 @@ public class Bullet extends BulletEntity implements TeamTrait, SyncT bullet.type = type; bullet.lifeScl = lifetimeScl; - //translate bullets backwards, purely for visual reasons - float backDelta = Timers.delta(); - - bullet.lastPosition().set(x - bullet.velocity.x * backDelta, y - bullet.velocity.y * backDelta, bullet.angle()); - bullet.setLastUpdated(TimeUtils.millis()); - bullet.setUpdateSpacing((long) ((Timers.delta() / 60f) * 1000)); bullet.set(x, y); - bullet.add(); + return bullet; } @@ -199,7 +192,7 @@ public class Bullet extends BulletEntity implements TeamTrait, SyncT super.update(); if(type.hitTiles && collidesTiles() && !supressCollision && initialized){ - world.raycastEach(world.toTile(lastPosition().x), world.toTile(lastPosition().y), world.toTile(x), world.toTile(y), (x, y) -> { + world.raycastEach(world.toTile(x), world.toTile(y), world.toTile(x + velocity.x), world.toTile(y + velocity.y), (x, y) -> { Tile tile = world.tile(x, y); if(tile == null) return false; diff --git a/core/src/io/anuke/mindustry/entities/effect/Lightning.java b/core/src/io/anuke/mindustry/entities/effect/Lightning.java index 8567b3770d..33033b23ba 100644 --- a/core/src/io/anuke/mindustry/entities/effect/Lightning.java +++ b/core/src/io/anuke/mindustry/entities/effect/Lightning.java @@ -114,6 +114,8 @@ public class Lightning extends SolidEntity implements Poolable, DrawTrait, SyncT return l; } + + @Override public void getHitbox(Rectangle rectangle){} diff --git a/core/src/io/anuke/mindustry/entities/traits/TargetTrait.java b/core/src/io/anuke/mindustry/entities/traits/TargetTrait.java index df50f23a1c..80753716c7 100644 --- a/core/src/io/anuke/mindustry/entities/traits/TargetTrait.java +++ b/core/src/io/anuke/mindustry/entities/traits/TargetTrait.java @@ -2,7 +2,6 @@ package io.anuke.mindustry.entities.traits; import io.anuke.mindustry.game.Team; import io.anuke.ucore.entities.trait.PosTrait; -import io.anuke.ucore.entities.trait.SolidTrait; import io.anuke.ucore.entities.trait.VelocityTrait; /** @@ -15,19 +14,11 @@ public interface TargetTrait extends PosTrait, VelocityTrait{ Team getTeam(); default float getTargetVelocityX(){ - if(this instanceof SolidTrait){ - return getX() - ((SolidTrait) this).lastPosition().x; - }else{ - return getVelocity().x; - } + return getVelocity().x; } default float getTargetVelocityY(){ - if(this instanceof SolidTrait){ - return getY() - ((SolidTrait) this).lastPosition().y; - }else{ - return getVelocity().y; - } + return getVelocity().y; } /** diff --git a/core/src/io/anuke/mindustry/entities/units/BaseUnit.java b/core/src/io/anuke/mindustry/entities/units/BaseUnit.java index 15b111772b..cfb403cb61 100644 --- a/core/src/io/anuke/mindustry/entities/units/BaseUnit.java +++ b/core/src/io/anuke/mindustry/entities/units/BaseUnit.java @@ -319,7 +319,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{ updateTargeting(); state.update(); - updateVelocityStatus(type.drag, type.maxVelocity); + updateVelocityStatus(); if(target != null) behavior(); @@ -344,6 +344,11 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{ } + @Override + public float getMaxVelocity(){ + return type.maxVelocity; + } + @Override public void removed(){ spawner = -1; diff --git a/core/src/io/anuke/mindustry/entities/units/GroundUnit.java b/core/src/io/anuke/mindustry/entities/units/GroundUnit.java index ae881872e6..ec71951c0f 100644 --- a/core/src/io/anuke/mindustry/entities/units/GroundUnit.java +++ b/core/src/io/anuke/mindustry/entities/units/GroundUnit.java @@ -119,7 +119,7 @@ public abstract class GroundUnit extends BaseUnit{ public void update(){ super.update(); - stuckTime = !vec.set(x, y).sub(lastPosition().x, lastPosition().y).isZero(0.0001f) ? 0f : stuckTime + Timers.delta(); + stuckTime = !getVelocity().isZero(0.0001f) ? 0f : stuckTime + Timers.delta(); if(!velocity.isZero(0.0001f) && (Units.invalidateTarget(target, this) || (distanceTo(target) > getWeapon().getAmmo().getRange()))){ rotation = Mathf.slerpDelta(rotation, velocity.angle(), type.rotatespeed); diff --git a/core/src/io/anuke/mindustry/world/blocks/defense/DeflectorWall.java b/core/src/io/anuke/mindustry/world/blocks/defense/DeflectorWall.java index bddfa0409e..a8aa57e19a 100644 --- a/core/src/io/anuke/mindustry/world/blocks/defense/DeflectorWall.java +++ b/core/src/io/anuke/mindustry/world/blocks/defense/DeflectorWall.java @@ -57,7 +57,7 @@ public class DeflectorWall extends Wall{ bullet.getHitbox(rect2); - Vector2 position = Physics.raycastRect(bullet.lastPosition().x, bullet.lastPosition().y, bullet.x, bullet.y, + Vector2 position = Physics.raycastRect(bullet.x, bullet.y, bullet.x + bullet.getVelocity().x, bullet.y + bullet.getVelocity().y, rect.setCenter(entity.x, entity.y).setSize(size * tilesize + rect2.width + rect2.height)); if(position != null){ @@ -70,7 +70,7 @@ public class DeflectorWall extends Wall{ bullet.getVelocity().y *= -1; } - bullet.updateVelocity(0f); + bullet.updateVelocity(); bullet.resetOwner(entity, Team.none); bullet.scaleTime(1f); bullet.supress(); From 8523e5bf6b7d4b88d74808216a616e0abfdb49c7 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 2 Oct 2018 18:47:23 -0400 Subject: [PATCH 3/6] Rectangles --- build.gradle | 2 +- core/src/io/anuke/mindustry/content/Mechs.java | 7 +++++++ .../src/io/anuke/mindustry/content/UnitTypes.java | 10 ++++++++-- core/src/io/anuke/mindustry/core/Logic.java | 3 ++- core/src/io/anuke/mindustry/entities/Player.java | 2 +- core/src/io/anuke/mindustry/entities/Unit.java | 15 +++++++++++++-- .../mindustry/entities/traits/TargetTrait.java | 7 +++++++ .../anuke/mindustry/entities/units/UnitType.java | 2 +- core/src/io/anuke/mindustry/type/Mech.java | 1 + 9 files changed, 41 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index e7a9c2f0b4..c030f9f3af 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ allprojects { appName = 'Mindustry' gdxVersion = '1.9.8' roboVMVersion = '2.3.0' - uCoreVersion = '1b74e58413f4885f204c441f88464d8c82c5433b' + uCoreVersion = 'ee0de709b7ab7bc993db42436a378ceee88c6460' getVersionString = { String buildVersion = getBuildVersion() diff --git a/core/src/io/anuke/mindustry/content/Mechs.java b/core/src/io/anuke/mindustry/content/Mechs.java index a26d6f16fd..b01c844dad 100644 --- a/core/src/io/anuke/mindustry/content/Mechs.java +++ b/core/src/io/anuke/mindustry/content/Mechs.java @@ -42,6 +42,7 @@ public class Mechs implements ContentList{ { drillPower = 1; mineSpeed = 1.5f; + mass = 1.2f; speed = 0.5f; boostSpeed = 0.85f; weapon = Weapons.blaster; @@ -81,6 +82,7 @@ public class Mechs implements ContentList{ speed = 0.75f; boostSpeed = 0.95f; itemCapacity = 15; + mass = 0.9f; armor = 30f; weaponOffsetX = -1; itemCapacity = 15; @@ -115,6 +117,7 @@ public class Mechs implements ContentList{ itemCapacity = 70; weaponOffsetY = -1; weaponOffsetX = 1; + mass = 1.75f; speed = 0.44f; drag = 0.35f; boostSpeed = 0.8f; @@ -157,6 +160,7 @@ public class Mechs implements ContentList{ itemCapacity = 50; speed = 0.36f; boostSpeed = 0.6f; + mass = 4f; shake = 4f; weaponOffsetX = 1; weaponOffsetY = 0; @@ -233,6 +237,7 @@ public class Mechs implements ContentList{ speed = 0.11f; maxSpeed = 10f; drag = 0.01f; + mass = 2f; armor = 5f; weapon = Weapons.missiles; trailColor = Color.valueOf("d3ddff"); @@ -287,6 +292,7 @@ public class Mechs implements ContentList{ speed = 0.12f; maxSpeed = 10f; drag = 0.035f; + mass = 2.5f; turnCursor = false; armor = 20f; itemCapacity = 30; @@ -309,6 +315,7 @@ public class Mechs implements ContentList{ speed = 0.32f; maxSpeed = 10f; drag = 0.06f; + mass = 3f; armor = 30f; itemCapacity = 60; trailColor = Color.valueOf("feb380"); diff --git a/core/src/io/anuke/mindustry/content/UnitTypes.java b/core/src/io/anuke/mindustry/content/UnitTypes.java index 6bbfca54db..a2b8125d71 100644 --- a/core/src/io/anuke/mindustry/content/UnitTypes.java +++ b/core/src/io/anuke/mindustry/content/UnitTypes.java @@ -48,6 +48,7 @@ public class UnitTypes implements ContentList{ maxVelocity = 1.1f; speed = 0.2f; drag = 0.4f; + mass = 1.75f; range = 40f; weapon = Weapons.chainBlaster; health = 130; @@ -57,7 +58,9 @@ public class UnitTypes implements ContentList{ maxVelocity = 0.8f; speed = 0.18f; drag = 0.4f; + mass = 3f; range = 10f; + hitsize = 8f; rotatespeed = 0.1f; weapon = Weapons.flamethrower; health = 440; @@ -67,7 +70,8 @@ public class UnitTypes implements ContentList{ maxVelocity = 0.8f; speed = 0.15f; drag = 0.4f; - mass = 4f; + mass = 4.5f; + hitsize = 10f; range = 10f; rotatespeed = 0.06f; weaponOffsetX = 1; @@ -89,6 +93,7 @@ public class UnitTypes implements ContentList{ health = 250; speed = 0.2f; maxVelocity = 1.4f; + mass = 3f; drag = 0.01f; isFlying = true; targetAir = false; @@ -97,7 +102,7 @@ public class UnitTypes implements ContentList{ revenant = new UnitType("revenant", Revenant.class, Revenant::new){{ health = 250; - mass = 4f; + mass = 5f; hitsize = 12f; speed = 0.14f; maxVelocity = 1.4f; @@ -109,6 +114,7 @@ public class UnitTypes implements ContentList{ phantom = new UnitType("phantom", Phantom.class, Phantom::new){{ isFlying = true; drag = 0.01f; + mass = 2f; speed = 0.2f; maxVelocity = 0.9f; range = 70f; diff --git a/core/src/io/anuke/mindustry/core/Logic.java b/core/src/io/anuke/mindustry/core/Logic.java index 355e30987d..fee3dc345d 100644 --- a/core/src/io/anuke/mindustry/core/Logic.java +++ b/core/src/io/anuke/mindustry/core/Logic.java @@ -172,12 +172,13 @@ public class Logic extends Module{ EntityQuery.collideGroups(group, playerGroup); for(EntityGroup other : unitGroups){ - if(other == group || other.isEmpty()) continue; + if(other.isEmpty()) continue; EntityQuery.collideGroups(group, other); } } EntityQuery.collideGroups(bulletGroup, playerGroup); + EntityQuery.collideGroups(playerGroup, playerGroup); world.pathfinder().update(); } diff --git a/core/src/io/anuke/mindustry/entities/Player.java b/core/src/io/anuke/mindustry/entities/Player.java index 0ce1564854..f81b6d3428 100644 --- a/core/src/io/anuke/mindustry/entities/Player.java +++ b/core/src/io/anuke/mindustry/entities/Player.java @@ -98,7 +98,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra @Override public void getHitbox(Rectangle rectangle){ - rectangle.setSize(5).setCenter(x, y); + rectangle.setSize(mech.hitsize).setCenter(x, y); } @Override diff --git a/core/src/io/anuke/mindustry/entities/Unit.java b/core/src/io/anuke/mindustry/entities/Unit.java index cdfd18c8de..38cc8e3dcc 100644 --- a/core/src/io/anuke/mindustry/entities/Unit.java +++ b/core/src/io/anuke/mindustry/entities/Unit.java @@ -16,6 +16,7 @@ import io.anuke.mindustry.world.blocks.Floor; import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Timers; import io.anuke.ucore.entities.impl.DestructibleEntity; +import io.anuke.ucore.entities.trait.DamageTrait; import io.anuke.ucore.entities.trait.DrawTrait; import io.anuke.ucore.entities.trait.SolidTrait; import io.anuke.ucore.graphics.Draw; @@ -49,6 +50,11 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ protected CarryTrait carrier; protected float drownTime; + @Override + public boolean movable(){ + return true; + } + @Override public UnitInventory getInventory(){ return inventory; @@ -94,8 +100,13 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ @Override public boolean collides(SolidTrait other){ - return true;//other instanceof DamageTrait && other - // instanceof TeamTrait && state.teams.areEnemies((((TeamTrait) other).getTeam()), team) && !isDead(); + if(isDead()) return true; + + if(other instanceof DamageTrait){ + return other instanceof TeamTrait && state.teams.areEnemies((((TeamTrait) other).getTeam()), team); + }else{ + return other instanceof Unit && ((Unit) other).isFlying() == isFlying(); + } } @Override diff --git a/core/src/io/anuke/mindustry/entities/traits/TargetTrait.java b/core/src/io/anuke/mindustry/entities/traits/TargetTrait.java index 80753716c7..bdeea6ea33 100644 --- a/core/src/io/anuke/mindustry/entities/traits/TargetTrait.java +++ b/core/src/io/anuke/mindustry/entities/traits/TargetTrait.java @@ -2,6 +2,7 @@ package io.anuke.mindustry.entities.traits; import io.anuke.mindustry.game.Team; import io.anuke.ucore.entities.trait.PosTrait; +import io.anuke.ucore.entities.trait.SolidTrait; import io.anuke.ucore.entities.trait.VelocityTrait; /** @@ -14,10 +15,16 @@ public interface TargetTrait extends PosTrait, VelocityTrait{ Team getTeam(); default float getTargetVelocityX(){ + if(this instanceof SolidTrait){ + return ((SolidTrait) this).getDeltaX(); + } return getVelocity().x; } default float getTargetVelocityY(){ + if(this instanceof SolidTrait){ + return ((SolidTrait) this).getDeltaY(); + } return getVelocity().y; } diff --git a/core/src/io/anuke/mindustry/entities/units/UnitType.java b/core/src/io/anuke/mindustry/entities/units/UnitType.java index 9703c1759f..6fa0e8627e 100644 --- a/core/src/io/anuke/mindustry/entities/units/UnitType.java +++ b/core/src/io/anuke/mindustry/entities/units/UnitType.java @@ -26,7 +26,7 @@ public class UnitType extends UnlockableContent{ public final String name; public final String description; public float health = 60; - public float hitsize = 5f; + public float hitsize = 7f; public float hitsizeTile = 4f; public float speed = 0.4f; public float range = 160; diff --git a/core/src/io/anuke/mindustry/type/Mech.java b/core/src/io/anuke/mindustry/type/Mech.java index 2d750b1711..d616e02aec 100644 --- a/core/src/io/anuke/mindustry/type/Mech.java +++ b/core/src/io/anuke/mindustry/type/Mech.java @@ -27,6 +27,7 @@ public class Mech extends UnlockableContent{ public float shake = 0f; public float armor = 1f; + public float hitsize = 6f; public float cellTrnsY = 0f; public float mineSpeed = 1f; public int drillPower = -1; From dd7f91b8c2627183a10aafb414d92f040620a100 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 2 Oct 2018 20:45:28 -0400 Subject: [PATCH 4/6] Fixed many various physics bugs --- build.gradle | 2 +- core/src/io/anuke/mindustry/content/Mechs.java | 8 -------- core/src/io/anuke/mindustry/content/UnitTypes.java | 3 +++ .../mindustry/content/blocks/TurretBlocks.java | 4 ++-- core/src/io/anuke/mindustry/entities/Unit.java | 4 ++-- .../io/anuke/mindustry/entities/bullet/Bullet.java | 4 ++-- .../anuke/mindustry/entities/units/GroundUnit.java | 14 ++++++-------- core/src/io/anuke/mindustry/type/Mech.java | 2 +- 8 files changed, 17 insertions(+), 24 deletions(-) diff --git a/build.gradle b/build.gradle index c030f9f3af..27bf254542 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ allprojects { appName = 'Mindustry' gdxVersion = '1.9.8' roboVMVersion = '2.3.0' - uCoreVersion = 'ee0de709b7ab7bc993db42436a378ceee88c6460' + uCoreVersion = '8b72f5b0fadc4a2133337d9db4651ac4794581d9' getVersionString = { String buildVersion = getBuildVersion() diff --git a/core/src/io/anuke/mindustry/content/Mechs.java b/core/src/io/anuke/mindustry/content/Mechs.java index b01c844dad..11145fcd73 100644 --- a/core/src/io/anuke/mindustry/content/Mechs.java +++ b/core/src/io/anuke/mindustry/content/Mechs.java @@ -46,7 +46,6 @@ public class Mechs implements ContentList{ speed = 0.5f; boostSpeed = 0.85f; weapon = Weapons.blaster; - maxSpeed = 4f; trailColorTo = Color.valueOf("ffd37f"); armor = 20f; } @@ -89,7 +88,6 @@ public class Mechs implements ContentList{ weaponOffsetY = -1; weapon = Weapons.shockgun; trailColorTo = Color.valueOf("d3ddff"); - maxSpeed = 5f; } @Override @@ -122,7 +120,6 @@ public class Mechs implements ContentList{ drag = 0.35f; boostSpeed = 0.8f; weapon = Weapons.healBlaster; - maxSpeed = 5f; armor = 15f; trailColorTo = Palette.heal; } @@ -166,7 +163,6 @@ public class Mechs implements ContentList{ weaponOffsetY = 0; weapon = Weapons.swarmer; trailColorTo = Color.valueOf("feb380"); - maxSpeed = 3.5f; armor = 45f; } @@ -218,7 +214,6 @@ public class Mechs implements ContentList{ drillPower = 1; mineSpeed = 0.9f; speed = 0.4f; - maxSpeed = 10f; drag = 0.1f; armor = 10f; weapon = Weapons.blasterSmall; @@ -235,7 +230,6 @@ public class Mechs implements ContentList{ { drillPower = -1; speed = 0.11f; - maxSpeed = 10f; drag = 0.01f; mass = 2f; armor = 5f; @@ -290,7 +284,6 @@ public class Mechs implements ContentList{ { drillPower = 2; speed = 0.12f; - maxSpeed = 10f; drag = 0.035f; mass = 2.5f; turnCursor = false; @@ -313,7 +306,6 @@ public class Mechs implements ContentList{ drillPower = 4; mineSpeed = 1.3f; speed = 0.32f; - maxSpeed = 10f; drag = 0.06f; mass = 3f; armor = 30f; diff --git a/core/src/io/anuke/mindustry/content/UnitTypes.java b/core/src/io/anuke/mindustry/content/UnitTypes.java index a2b8125d71..52bc0ebc84 100644 --- a/core/src/io/anuke/mindustry/content/UnitTypes.java +++ b/core/src/io/anuke/mindustry/content/UnitTypes.java @@ -24,6 +24,8 @@ public class UnitTypes implements ContentList{ maxVelocity = 1.7f; range = 40f; health = 45; + hitsize = 4f; + mass = 0.1f; weapon = Weapons.droneBlaster; trailColor = Color.valueOf("ffd37f"); } @@ -84,6 +86,7 @@ public class UnitTypes implements ContentList{ speed = 0.3f; maxVelocity = 1.9f; drag = 0.01f; + mass = 1.5f; weapon = Weapons.chainBlaster; isFlying = true; health = 70; diff --git a/core/src/io/anuke/mindustry/content/blocks/TurretBlocks.java b/core/src/io/anuke/mindustry/content/blocks/TurretBlocks.java index 36be5fdc71..8d16feb64a 100644 --- a/core/src/io/anuke/mindustry/content/blocks/TurretBlocks.java +++ b/core/src/io/anuke/mindustry/content/blocks/TurretBlocks.java @@ -190,8 +190,8 @@ public class TurretBlocks extends BlockList implements ContentList{ cyclone = new ItemTurret("cyclone"){{ ammoTypes = new AmmoType[]{AmmoTypes.flakExplosive, AmmoTypes.flakPlastic, AmmoTypes.flakSurge}; xRand = 4f; - reload = 10f; - range = 140f; + reload = 8f; + range = 145f; size = 3; recoil = 3f; rotatespeed = 10f; diff --git a/core/src/io/anuke/mindustry/entities/Unit.java b/core/src/io/anuke/mindustry/entities/Unit.java index 38cc8e3dcc..b21dcb9e5a 100644 --- a/core/src/io/anuke/mindustry/entities/Unit.java +++ b/core/src/io/anuke/mindustry/entities/Unit.java @@ -206,8 +206,8 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ velocity.limit(getMaxVelocity()).scl(status.getSpeedMultiplier()); if(isFlying()){ - x += velocity.x / getMass() * Timers.delta(); - y += velocity.y / getMass() * Timers.delta(); + x += velocity.x * Timers.delta(); + y += velocity.y * Timers.delta(); }else{ boolean onLiquid = floor.isLiquid; diff --git a/core/src/io/anuke/mindustry/entities/bullet/Bullet.java b/core/src/io/anuke/mindustry/entities/bullet/Bullet.java index 4910df3a40..484f1c735f 100644 --- a/core/src/io/anuke/mindustry/entities/bullet/Bullet.java +++ b/core/src/io/anuke/mindustry/entities/bullet/Bullet.java @@ -68,7 +68,7 @@ public class Bullet extends BulletEntity implements TeamTrait, SyncT bullet.type = type; bullet.lifeScl = lifetimeScl; - bullet.set(x, y); + bullet.set(x - bullet.velocity.x * Timers.delta(), y - bullet.velocity.y * Timers.delta()); bullet.add(); return bullet; @@ -192,7 +192,7 @@ public class Bullet extends BulletEntity implements TeamTrait, SyncT super.update(); if(type.hitTiles && collidesTiles() && !supressCollision && initialized){ - world.raycastEach(world.toTile(x), world.toTile(y), world.toTile(x + velocity.x), world.toTile(y + velocity.y), (x, y) -> { + world.raycastEach(world.toTile(lastPosition().x), world.toTile(lastPosition().y), world.toTile(x), world.toTile(y), (x, y) -> { Tile tile = world.tile(x, y); if(tile == null) return false; diff --git a/core/src/io/anuke/mindustry/entities/units/GroundUnit.java b/core/src/io/anuke/mindustry/entities/units/GroundUnit.java index ec71951c0f..b0d5aab067 100644 --- a/core/src/io/anuke/mindustry/entities/units/GroundUnit.java +++ b/core/src/io/anuke/mindustry/entities/units/GroundUnit.java @@ -125,6 +125,10 @@ public abstract class GroundUnit extends BaseUnit{ rotation = Mathf.slerpDelta(rotation, velocity.angle(), type.rotatespeed); } + if(!velocity.isZero()){ + baseRotation = Mathf.slerpDelta(baseRotation, velocity.angle(), 0.05f); + } + if(stuckTime < 1f){ walkTime += Timers.delta(); } @@ -268,10 +272,7 @@ public abstract class GroundUnit extends BaseUnit{ if(tile == targetTile) return; - vec.trns(baseRotation, type.speed); - - baseRotation = Mathf.slerpDelta(baseRotation, angleTo(targetTile), 0.05f); - velocity.add(vec); + velocity.add(vec.trns(angleTo(targetTile), type.speed)); } protected void moveAwayFromCore(){ @@ -292,9 +293,6 @@ public abstract class GroundUnit extends BaseUnit{ if(tile == targetTile || core == null || distanceTo(core) < 90f) return; - vec.trns(baseRotation, type.speed); - - baseRotation = Mathf.slerpDelta(baseRotation, angleTo(targetTile), 0.05f); - velocity.add(vec); + velocity.add(vec.trns(angleTo(targetTile), type.speed)); } } diff --git a/core/src/io/anuke/mindustry/type/Mech.java b/core/src/io/anuke/mindustry/type/Mech.java index d616e02aec..92c11cfdf4 100644 --- a/core/src/io/anuke/mindustry/type/Mech.java +++ b/core/src/io/anuke/mindustry/type/Mech.java @@ -20,7 +20,7 @@ public class Mech extends UnlockableContent{ public boolean flying; public float speed = 1.1f; - public float maxSpeed = 1.1f; + public float maxSpeed = 10f; public float boostSpeed = 0.75f; public float drag = 0.4f; public float mass = 1f; From ce4031af74fc32976f79164158246ff8295392b4 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 2 Oct 2018 21:44:32 -0400 Subject: [PATCH 5/6] Additional bugfixes --- build.gradle | 2 +- core/src/io/anuke/mindustry/content/UnitTypes.java | 7 ++++--- core/src/io/anuke/mindustry/entities/units/GroundUnit.java | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 27bf254542..29d3536ec7 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ allprojects { appName = 'Mindustry' gdxVersion = '1.9.8' roboVMVersion = '2.3.0' - uCoreVersion = '8b72f5b0fadc4a2133337d9db4651ac4794581d9' + uCoreVersion = 'ad9936bf6ebba8cd5b3a654b8973408f7101dc7d' getVersionString = { String buildVersion = getBuildVersion() diff --git a/core/src/io/anuke/mindustry/content/UnitTypes.java b/core/src/io/anuke/mindustry/content/UnitTypes.java index 52bc0ebc84..9b22c378cd 100644 --- a/core/src/io/anuke/mindustry/content/UnitTypes.java +++ b/core/src/io/anuke/mindustry/content/UnitTypes.java @@ -50,6 +50,7 @@ public class UnitTypes implements ContentList{ maxVelocity = 1.1f; speed = 0.2f; drag = 0.4f; + hitsize = 8f; mass = 1.75f; range = 40f; weapon = Weapons.chainBlaster; @@ -60,9 +61,9 @@ public class UnitTypes implements ContentList{ maxVelocity = 0.8f; speed = 0.18f; drag = 0.4f; - mass = 3f; + mass = 3.5f; range = 10f; - hitsize = 8f; + hitsize = 9f; rotatespeed = 0.1f; weapon = Weapons.flamethrower; health = 440; @@ -72,7 +73,7 @@ public class UnitTypes implements ContentList{ maxVelocity = 0.8f; speed = 0.15f; drag = 0.4f; - mass = 4.5f; + mass = 5f; hitsize = 10f; range = 10f; rotatespeed = 0.06f; diff --git a/core/src/io/anuke/mindustry/entities/units/GroundUnit.java b/core/src/io/anuke/mindustry/entities/units/GroundUnit.java index b0d5aab067..19451d739d 100644 --- a/core/src/io/anuke/mindustry/entities/units/GroundUnit.java +++ b/core/src/io/anuke/mindustry/entities/units/GroundUnit.java @@ -119,7 +119,7 @@ public abstract class GroundUnit extends BaseUnit{ public void update(){ super.update(); - stuckTime = !getVelocity().isZero(0.0001f) ? 0f : stuckTime + Timers.delta(); + stuckTime = !vec.set(x, y).sub(lastPosition()).isZero(0.0001f) ? 0f : stuckTime + Timers.delta(); if(!velocity.isZero(0.0001f) && (Units.invalidateTarget(target, this) || (distanceTo(target) > getWeapon().getAmmo().getRange()))){ rotation = Mathf.slerpDelta(rotation, velocity.angle(), type.rotatespeed); From f0cacf6bd505c774d1f1371a9447fb68268f8e3a Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 2 Oct 2018 23:33:43 -0400 Subject: [PATCH 6/6] Final physics edit, ready to merge --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 29d3536ec7..539d6f8114 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ allprojects { appName = 'Mindustry' gdxVersion = '1.9.8' roboVMVersion = '2.3.0' - uCoreVersion = 'ad9936bf6ebba8cd5b3a654b8973408f7101dc7d' + uCoreVersion = '00d05bd7d3e943c8a454ccf2cb69cdffb23afbb7' getVersionString = { String buildVersion = getBuildVersion()