Better physics

This commit is contained in:
Anuken
2020-02-08 15:39:27 -05:00
parent 8814dbe29a
commit ba1f59aa71
9 changed files with 34 additions and 9 deletions

View File

@@ -268,11 +268,12 @@ public class Blocks implements ContentList{
}}; }};
ice = new Floor("ice"){{ ice = new Floor("ice"){{
dragMultiplier = 0.6f; dragMultiplier = 0.35f;
attributes.set(Attribute.water, 0.4f); attributes.set(Attribute.water, 0.4f);
}}; }};
iceSnow = new Floor("ice-snow"){{ iceSnow = new Floor("ice-snow"){{
dragMultiplier = 0.6f;
variants = 3; variants = 3;
attributes.set(Attribute.water, 0.3f); attributes.set(Attribute.water, 0.3f);
}}; }};

View File

@@ -22,8 +22,8 @@ public class UnitTypes implements ContentList{
public void load(){ public void load(){
dagger = new UnitDef("dagger"){{ dagger = new UnitDef("dagger"){{
speed = 0.2f; speed = 1f;
drag = 0.2f; drag = 0.3f;
hitsize = 8f; hitsize = 8f;
mass = 1.75f; mass = 1.75f;
health = 130; health = 130;
@@ -37,7 +37,7 @@ public class UnitTypes implements ContentList{
}}; }};
vanguard = new UnitDef("vanguard"){{ vanguard = new UnitDef("vanguard"){{
speed = 0.3f; speed = 1.3f;
drag = 0.1f; drag = 0.1f;
hitsize = 8f; hitsize = 8f;
mass = 1.75f; mass = 1.75f;

View File

@@ -4,6 +4,7 @@ import arc.math.*;
import arc.math.geom.*; import arc.math.geom.*;
import arc.util.*; import arc.util.*;
import mindustry.annotations.Annotations.*; import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.world.blocks.*; import mindustry.world.blocks.*;
@@ -30,6 +31,19 @@ abstract class FlyingComp implements Posc, Velc, Healthc, Hitboxc{
return isGrounded(); return isGrounded();
} }
void moveAt(Vec2 vector){
Floor on = isFlying() ? Blocks.air.asFloor() : floorOn();
Vec2 t = Tmp.v3.set(vector).scl(floorSpeedMultiplier()); //target vector
float mag = Tmp.v3.len();
vel.x = Mathf.approach(vel.x, t.x, mag);
vel.y = Mathf.approach(vel.y, t.y, mag);
}
float floorSpeedMultiplier(){
Floor on = isFlying() ? Blocks.air.asFloor() : floorOn();
return on.speedMultiplier;
}
@Override @Override
public void update(){ public void update(){
Floor floor = floorOn(); Floor floor = floorOn();

View File

@@ -7,7 +7,7 @@ import mindustry.gen.*;
abstract class MassComp implements Velc{ abstract class MassComp implements Velc{
float mass = 1f; float mass = 1f;
public void applyImpulse(float x, float y){ public void impulse(float x, float y){
vel().add(x / mass, y / mass); vel().add(x / mass, y / mass);
} }
} }

View File

@@ -83,6 +83,8 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox
@Override @Override
public void update(){ public void update(){
drag(type.drag * (isGrounded() ? (floorOn().dragMultiplier) : 1f));
//apply knockback based on spawns //apply knockback based on spawns
//TODO move elsewhere //TODO move elsewhere
if(team() != state.rules.waveTeam){ if(team() != state.rules.waveTeam){

View File

@@ -1,8 +1,10 @@
package mindustry.entities.def; package mindustry.entities.def;
import mindustry.annotations.Annotations.*; import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.entities.*; import mindustry.entities.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.world.blocks.*;
import static mindustry.Vars.collisions; import static mindustry.Vars.collisions;
@@ -29,5 +31,11 @@ abstract class WaterMoveComp implements Posc, Velc, Hitboxc, Flyingc{
public boolean canDrown(){ public boolean canDrown(){
return false; return false;
} }
@Replace
public float floorSpeedMultiplier(){
Floor on = isFlying() ? Blocks.air.asFloor() : floorOn();
return on.isDeep() ? 1.3f : 1f;
}
} }

View File

@@ -504,11 +504,11 @@ public class DesktopInput extends InputHandler{
Vec2 movement = Tmp.v1.set(speed * xa, speed * ya).limit(speed); Vec2 movement = Tmp.v1.set(speed * xa, speed * ya).limit(speed);
if(omni){ if(omni){
unit.vel().add(movement); unit.moveAt(movement);
unit.lookAt(Angles.mouseAngle(unit.x(), unit.y())); unit.lookAt(Angles.mouseAngle(unit.x(), unit.y()));
}else{ }else{
if(!unit.vel().isZero(0.01f)) unit.rotation(unit.vel().angle()); if(!unit.vel().isZero(0.01f)) unit.rotation(unit.vel().angle());
unit.vel().add(Tmp.v2.trns(unit.rotation(), movement.len())); unit.moveAt(Tmp.v2.trns(unit.rotation(), movement.len()));
if(!movement.isZero()) unit.vel().rotateTo(movement.angle(), unit.type().rotateSpeed * Time.delta()); if(!movement.isZero()) unit.vel().rotateTo(movement.angle(), unit.type().rotateSpeed * Time.delta());
} }

View File

@@ -162,7 +162,7 @@ public class Conveyor extends Block implements Autotiler{
} }
if(entity.len * itemSpace < 0.9f){ if(entity.len * itemSpace < 0.9f){
unit.applyImpulse((tx * speed + centerx) * entity.delta(), (ty * speed + centery) * entity.delta()); unit.impulse((tx * speed + centerx) * entity.delta(), (ty * speed + centery) * entity.delta());
} }
} }

View File

@@ -1,3 +1,3 @@
org.gradle.daemon=true org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=b2996f736d5b6870913f5d8b5496fe6033069ac8 archash=0328073f1993cd1d72a237781c3cc1f82395234b