Fixed many various physics bugs

This commit is contained in:
Anuken
2018-10-02 20:45:28 -04:00
parent 8523e5bf6b
commit dd7f91b8c2
8 changed files with 17 additions and 24 deletions
@@ -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;
@@ -68,7 +68,7 @@ public class Bullet extends BulletEntity<BulletType> 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<BulletType> 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;
@@ -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));
}
}