less (less) terrible physics

This commit is contained in:
Anuken
2018-11-04 15:49:23 -05:00
parent 5f1addc54d
commit 192814650d
6 changed files with 31 additions and 11 deletions

View File

@ -25,7 +25,7 @@ allprojects {
appName = 'Mindustry'
gdxVersion = '1.9.8'
roboVMVersion = '2.3.0'
uCoreVersion = 'f5ae8c0d58b6b7b42e95e57114220b11beb43fb3'
uCoreVersion = '1042ca8a3959a1354f5249acc89e396035a3f266'
getVersionString = {
String buildVersion = getBuildVersion()

View File

@ -495,6 +495,8 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
spawner = -1;
}
avoidOthers(1f);
Tile tile = world.tileWorld(x, y);
boostHeat = Mathf.lerpDelta(boostHeat, (tile != null && tile.solid()) || (isBoosting && ((!movement.isZero() && moved) || !isLocal)) ? 1f : 0f, 0.08f);

View File

@ -2,6 +2,7 @@ package io.anuke.mindustry.entities;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.entities.traits.*;
@ -39,6 +40,9 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
/**Maximum absolute value of a velocity vector component.*/
public static final float maxAbsVelocity = 127f / velocityPercision;
private static final Rectangle queryRect = new Rectangle();
private static final Vector2 moveVector = new Vector2();
public final UnitInventory inventory = new UnitInventory(this);
public float rotation;
public float hitTime;
@ -182,6 +186,18 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
return status.hasEffect(effect);
}
public void avoidOthers(float scaling){
getHitbox(queryRect);
queryRect.setSize(queryRect.getWidth() * scaling);
Units.getNearby(queryRect, t -> {
if(t == this || t.getCarrier() == this || getCarrier() == t || t.isFlying() != isFlying()) return;
float dst = distanceTo(t);
moveVector.set(x, y).sub(t.getX(), t.getY()).setLength(1f * (1f - (dst / queryRect.getWidth())));
applyImpulse(moveVector.x, moveVector.y);
});
}
public TileEntity getClosestCore(){
TeamData data = state.teams.get(team);

View File

@ -41,6 +41,7 @@ import static io.anuke.mindustry.Vars.*;
/**Base class for AI units.*/
public abstract class BaseUnit extends Unit implements ShooterTrait{
protected static int timerIndex = 0;
protected static final int timerTarget = timerIndex++;
@ -305,11 +306,10 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
return;
}
if(!Net.client()){
avoidOthers(1.2f);
if(spawner != -1 && (world.tile(spawner) == null || world.tile(spawner).entity == null)){
damage(health);
}
if(spawner != -1 && (world.tile(spawner) == null || world.tile(spawner).entity == null)){
damage(health);
}
if(squad != null){

View File

@ -121,10 +121,6 @@ public abstract class GroundUnit extends BaseUnit{
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);
}
if(!velocity.isZero()){
baseRotation = Mathf.slerpDelta(baseRotation, velocity.angle(), 0.05f);
}
@ -249,6 +245,8 @@ public abstract class GroundUnit extends BaseUnit{
if((tile == null || tile.solid() || tile.floor().drownTime > 0) || stuckTime > 10f){
baseRotation += Mathf.sign(id % 2 - 0.5f) * Timers.delta() * 3f;
}
rotation = Mathf.slerpDelta(rotation, velocity.angle(), type.rotatespeed);
}
protected void circle(float circleLength){
@ -272,7 +270,10 @@ public abstract class GroundUnit extends BaseUnit{
if(tile == targetTile) return;
float angle = angleTo(targetTile);
velocity.add(vec.trns(angleTo(targetTile), type.speed));
rotation = Mathf.slerpDelta(rotation, angle, type.rotatespeed);
}
protected void moveAwayFromCore(){
@ -293,6 +294,9 @@ public abstract class GroundUnit extends BaseUnit{
if(tile == targetTile || core == null || distanceTo(core) < 90f) return;
float angle = angleTo(targetTile);
velocity.add(vec.trns(angleTo(targetTile), type.speed));
rotation = Mathf.slerpDelta(rotation, angle, type.rotatespeed);
}
}

View File

@ -296,8 +296,6 @@ public class Sectors{
return null;
});
}